You can use an appearance proxy to set particular appearance properties for all instances of a view in your application. For example, if you want all sliders in your app to have a particular
minimum track tint color, you can specify this with a single message to the slider’s appearance proxy.
There are two ways to customize appearance for objects: for all instances and for instances contained within an instance of a container class.
- To customize the appearance of all instances of a class, use appearance to get the appearance proxy for the class.
- [[UISlider appearance] setMinimumTrackTintColor:[UIColor greenColor]];
- To customize the appearances for instances of a class when contained within an instance of a container class, or instances in a hierarchy, you use appearanceWhenContainedIn: to get
- the appearance proxy for the class.
- [UISlider appearanceWhenContainedIn:[UIView class], nil] setMinimumTrackTintColor:[UIColor greenColor]];
以上文字来自:苹果的官方文档中的 About View,如下图所示:
上面的大致意思是:有两种方法来设定某个对象的显示效果:
一个是设置该对象所有实例,一个是设置包含在某个容器类中所有该对象实例的显示效果;
接着就是两种实现方式:
一、
[[UISlider appearance] setMinimumTrackTintColor:[UIColor greenColor]];
这条语句可以将App中用到的所有UISlider左边颜色为绿色
二、 [UISlider appearanceWhenContainedIn:[ UIScrollView class], nil] setMinimumTrackTintColor:[UIColor greenColor]];
二、 [UISlider appearanceWhenContainedIn:[ UIScrollView class], nil] setMinimumTrackTintColor:[UIColor greenColor]];
这条语句可以将App中用到的所有父视图为
UIScrollView的UISlider左边颜色为绿色
如下图是“二”的效果: