UI控件(UISlider)

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    UISlider* slider = [[UISlider alloc]init];
    slider.frame = CGRectMake(10, 20, 250, 50);
    slider.minimumValue = 0;
    slider.maximumValue = 100;
    
    slider.minimumTrackTintColor = [UIColor yellowColor];//定义滑块左侧颜色
    slider.maximumTrackTintColor = [UIColor blueColor];//定义滑块右侧颜色
    //slider.thumbTintColor = [UIColor redColor];//定义滑块颜色
    
    //设置滑块的图案
    [slider setThumbImage:[UIImage imageNamed:@"icon.png"] forState:UIControlStateNormal];
    
    //@selector在有参数的情况,必须加:
    [slider addTarget:self action:@selector(sliderChanged:) forControlEvents:UIControlEventValueChanged];
    
    [self.view addSubview:slider];
}

-(void)sliderChanged:(id)sender{
    UISlider* slider = sender;
    NSLog(@"%f", slider.value);
}

@end

 

你可能感兴趣的:(UI控件(UISlider))