App中控件全局显示外观的设置 Appearance Proxies

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]];
这条语句可以将App中用到的所有父视图为 UIScrollView的UISlider左边颜色为绿色
如下图是“二”的效果:


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值