// Slider
self.slider = [[UISlider alloc] initWithFrame:CGRectMake(100, 50, 200, 30)];
self.slider.backgroundColor = [UIColor clearColor];
[self.view addSubview:self.slider];
[self.slider addTarget:self action:@selector(sliderAction:) forControlEvents:UIControlEventValueChanged];
self.slider.value = 2;
self.slider.maximumValue = 2;
self.slider.minimumValue = 0.1;
// 用segement实现更换view背景颜色
NSArray *arr = [NSArray arrayWithObjects:@"红", @"黄", @"绿", nil];
self.segment = [[UISegmentedControl alloc] initWithItems:arr];
self.segment.frame = CGRectMake(90, 50, 200, 30);
[self.view addSubview:self.segment];
[self.segment release];
[self.segment addTarget:self action:@selector(segementAction:)forControlEvents:UIControlEventValueChanged];
// 点击方法
- (void)segementAction:(UISegmentedControl *)segement {
NSInteger select = self.segment.selectedSegmentIndex;
switch (select) {
case 0:
self.view.backgroundColor = [UIColor redColor];
break;
case 1:
self.view.backgroundColor = [UIColor yellowColor];
break;
case 2:
self.view.backgroundColor = [UIColor greenColor];
default:
break;
}
}