UI - UISwitchAndUIActivityIndicatorView

来源:互联网 发布:战舰世界mac 国服 编辑:程序博客网 时间:2024/06/10 20:06

本文章介绍了 UISwitch, UIActivityIndicatorView的相关属性及使用

#import "ViewController.h"@interface ViewController () <UIAlertViewDelegate>@property (nonatomic, strong) UISwitch *btSwitch;@property (nonatomic, strong) UIActivityIndicatorView *indicatorView;@end@implementation ViewController- (void)viewDidLoad {    [super viewDidLoad];    // Do any additional setup after loading the view, typically from a nib.        //UISwitch    [self configureUISwitchOnTheView];    //UIActivityIndicatorView    [self configureUIActivityIndicatorViewOnTheView];//    //UIAlertView//    [self configureAlertViewOnTheView];}

UISwitch

- (void)configureUISwitchOnTheView{    self.btSwitch = [[UISwitch alloc] initWithFrame:CGRectMake(50, 50, 100, 20)];    //开状态下,渲染颜色    _btSwitch.onTintColor = [UIColor redColor];    //关状态下,渲染颜色    _btSwitch.tintColor = [UIColor blueColor];    //滑块颜色    _btSwitch.thumbTintColor = [UIColor lightGrayColor];    //开状态下图片,官方文档说明:In iOS 7, this property has no effect.    UIImage *pic1 = [[UIImage imageNamed:@"aaa.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];    _btSwitch.onImage = pic1;    //关状态下图片,官方文档说明:In iOS 7, this property has no effect.    UIImage *pic2 = [[UIImage imageNamed:@"bbb.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];    _btSwitch.offImage = pic2;    //设置开关默认状态,默认为关;在此不会出发点击事件    _btSwitch.on = NO;    [_btSwitch setOn:YES animated:YES];    //点击事件    [_btSwitch addTarget:self action:@selector(clicikSwitch:) forControlEvents:UIControlEventValueChanged];    [self.view addSubview:_btSwitch];}- (void)clicikSwitch:(UISwitch *)swit{    if (swit.on) {        NSLog(@"开");    }else{        NSLog(@"关");    }}



UIActivityIndicatorView

- (void)configureUIActivityIndicatorViewOnTheView{    self.indicatorView = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(200, 50, 100, 100)];    /**     * 指示器风格:     UIActivityIndicatorViewStyleWhiteLarge 大型白色指示器     UIActivityIndicatorViewStyleWhite 标准尺寸白色指示器  (默认样式)     UIActivityIndicatorViewStyleGray 灰色指示器,用于白色背景     */    _indicatorView.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;    //指示器停止后自动隐藏,默认 YES    _indicatorView.hidesWhenStopped = NO;    //指示器的颜色,风格设置也会影响指示器颜色,此两个属性的先后顺序需要注意    _indicatorView.color = [UIColor redColor];    //开启指示器动画    [_indicatorView startAnimating];    //关闭指示器动画//    [_indicatorView stopAnimating];    //根据指示器状态做出判断    if ([_indicatorView isAnimating]) {        NSLog(@"当前指示器状态为开");    }    [self.view addSubview:_indicatorView];}


0 0
原创粉丝点击