自定义UISlider的样式和滑块

//自定义UISlider的样式和滑块

    

    //轨道图片

    UIImage *stetchLeftTrack = [UIImage imageNamed:@"thick"];

    UIImage *stetchRightTrack = [UIImage imageNamed:@"thick"];

    

    //滑块图片

    UIImage *thumbImage = [UIImage imageNamed:@"thumb"];

    

    //创建slider

    UISlider *slider = [[UISlider alloc] initWithFrame:CGRectMake(30, 300, 300, 7)];

    slider.backgroundColor = [UIColor clearColor];

    slider.value = 1.0;

    slider.minimumValue = 0.5;

    slider.maximumValue = 1.0;

    

    //设置轨道的图片

    [slider setMinimumTrackImage:stetchLeftTrack forState:UIControlStateNormal];

    [slider setMaximumTrackImage:stetchRightTrack forState:UIControlStateNormal];

    

    //设置滑块的图片

    //[slider setThumbImage:thumbImage forState:UIControlStateHighlighted];

    [slider setThumbImage:thumbImage forState:UIControlStateNormal];

    

    //滑动滑块添加事件

    //滑动过程中不断触发事件

    [slider addTarget:self action:@selector(onThumb:) forControlEvents:UIControlEventValueChanged];

    //滑动完成添加事件

    //滑动完成后触发事件

    [slider addTarget:self action:@selector(endThumb:) forControlEvents:UIControlEventTouchUpInside];

    

    [self addSubview:slider];

    


你可能感兴趣的:(iOS,布局)