- (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];

}

slider.transform = CGAffineTransformMakeRotation( M_PI * 0.5 );垂直

-(void)buttonslider:(UIView *)serder

{

UISlider *hange = (UISlider *)serder;

NSLog(@"%f",hange.value);

}

04-24 12:54