UI - UISwitchAndUIActivityIndicatorView

2765 ワード

この記事では、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];
}