Custom UISlider

2020-05-27 11:45发布

How to customize UISlider?(change style,background,...)

3条回答
欢心
2楼-- · 2020-05-27 11:53

IF you want some example code I could recommend you to look at Apple's example code project UICatalog. This project gives you some basic knowledge about many of the UI elements. In the example they have a custom slider with different colors to the default UISlider.

查看更多
我想做一个坏孩纸
3楼-- · 2020-05-27 12:00

Read the documentation: UISlider Class Reference

Have a close look at the following methods:

Changing the Slider’s Appearance

setMinimumTrackImage:forState:
setMaximumTrackImage:forState:
setThumbImage:forState:

For background have a look at UIView documentation.

查看更多
Emotional °昔
4楼-- · 2020-05-27 12:03

You can go through this tutorial for customizing the controls.

For customizing UISlider,use this piece of code from this tutorial.

UIImage *minImage = [[UIImage imageNamed:@"slider_minimum.png"] 
    resizableImageWithCapInsets:UIEdgeInsetsMake(0, 5, 0, 0)];
UIImage *maxImage = [[UIImage imageNamed:@"slider_maximum.png"] 
    resizableImageWithCapInsets:UIEdgeInsetsMake(0, 5, 0, 0)];
UIImage *thumbImage = [UIImage imageNamed:@"thumb.png"];

     [[UISlider appearance] setMaximumTrackImage:maxImage 
        forState:UIControlStateNormal];
    [[UISlider appearance] setMinimumTrackImage:minImage 
        forState:UIControlStateNormal];
    [[UISlider appearance] setThumbImage:thumbImage 
        forState:UIControlStateNormal];
查看更多
登录 后发表回答