标签:
- (void)viewDidLoad { [super viewDidLoad]; [self buttonswitch]; [self buttonslider]; } -(void)buttonswitch { // UIswitch self.view.backgroundColor = [UIColor whiteColor]; UISwitch *switc = [[UISwitch alloc]init]; switc.frame = CGRectMake(50, 50, 50, 50); switc.thumbTintColor = [UIColor redColor]; switc.onTintColor = [UIColor blackColor]; switc.tintColor = [UIColor yellowColor]; [switc addTarget:self action:@selector(buttonswitch:) forControlEvents:UIControlEventValueChanged]; [self.view addSubview:switc]; } -(void)buttonswitch:(UIView *)serder { UISwitch *change = (UISwitch *)serder; BOOL tees = change.isOn; if (tees==YES) { self.view.backgroundColor = [UIColor grayColor]; }else { self.view.backgroundColor = [UIColor brownColor]; } } -(void)buttonslider { // UIslider UISlider *slider = [[UISlider alloc]initWithFrame:CGRectMake(50, 100, 200, 10)]; slider.maximumValue = 1.0; slider.minimumValue = 0.0; slider.maximumTrackTintColor = [UIColor yellowColor]; slider.minimumTrackTintColor = [UIColor brownColor]; slider.thumbTintColor = [UIColor redColor]; [slider addTarget:self action:@selector(buttonslider:) forControlEvents:UIControlEventValueChanged]; [self.view addSubview:slider]; } -(void)buttonslider:(UIView *)serder { UISlider *hange = (UISlider *)serder; NSLog(@"%f",hange.value); }标签:
原文地址:http://www.cnblogs.com/daijiahong/p/4485029.html