How to customize UISlider?(change style,background,...)
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
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];
回答2:
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.
回答3:
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.