Objective-C Learning Notes - UISwitch2
终于有一个正常一点的样例程序了,什么鬼排版啊!!!
简单演示 UISwitch 的常用属性, isOn...
冲个凉先,等下再继续 wwww
#import <UIKit/UIKit.h> @interface ViewController : UIViewController{ UISwitch *leftSwitch; UISwitch *rightSwitch; } @property (retain, nonatomic) UISwitch *leftSwitch; @property (retain, nonatomic) UISwitch *rightSwitch; @end
#import "ViewController.h" @interface ViewController () @end @implementation ViewController @synthesize leftSwitch,rightSwitch; - (void)viewDidLoad { [super viewDidLoad]; leftSwitch = [[UISwitch alloc]initWithFrame:CGRectMake(0, 20, 40, 20)]; rightSwitch = [[UISwitch alloc]initWithFrame:CGRectMake(0, 240, 40, 20)]; [leftSwitch addTarget:self action:@selector(switchChanged:) forControlEvents:UIControlEventValueChanged]; [self.view addSubview:leftSwitch]; [rightSwitch addTarget:self action:@selector(switchChanged:) forControlEvents:UIControlEventValueChanged]; [self.view addSubview:rightSwitch]; // Do any additional setup after loading the view, typically from a nib. } - (void)switchChanged:(id)sender{ UISwitch *mySwitch = (UISwitch *)sender; BOOL setting = mySwitch.isOn; if (setting){ NSLog(@"YES"); }else{ NSLog(@"NO"); } [leftSwitch setOn:setting animated:YES]; [rightSwitch setOn:setting animated:YES]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end