iOS @property之后跟着UI_APPEARANCE_SELECTOR

来源:互联网 发布:七氟烷的mac值是多少 编辑:程序博客网 时间:2024/05/28 23:21

appearance是apple在iOS5.0上加的一个协议,它让程序员可以很轻松地改变某控件的全局样式(背景)

  @selector(appearance)
  支持UIAppearance协议的类可以访问appearance selector ,它为receiver返回appearance proxy,我么可以给proxy发一些消息,诸如setTintColor:等

但是它并不是支持所有的UI类。下面列出它支持的类

  1.UIActivitiIndicatorView

  2.UIBarButtonItem

  3.UIBarItem

  4.UINavgationBar

  5.UIPopoverControll

  6.UIProgressView

  7.UISearchBar

  8.UISegmentControll

  9.UISlider

  10.UISwitch

  11.UITabBar

  12.UITabBarItem

  13.UIToolBar

  14.UIView

  15.UIViewController

例如:

[[UINavigationBarappearance] setTintColor:[UIColorblackColor]];

[[UISearchBarappearance] setTintColor:[UIColorblackColor]];


特殊地:
开关控件 @property(nullable, nonatomic, strong) UIColor *onTintColor NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR;

可以统一设置开关的onTintColor样式.不过开关控件的颜色属性比较特殊

1.只在添加时作用一次.

2.添加结束后.

3.以后设置便不再改变.

4.也可以移出开关的父控件.而把开关从新加入到window上.

在iOS属性后有UI_APPEARANCE_SELECTOR标志都可以一次性统一设置.这种情况还有很多.比如说统一设置UITabbarItem的文字颜色 方法如下:

  • (void)setTitleTextAttributes:(nullable NSDictionary*)attributes forState:(UIControlState)state NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR;

原文链接:http://www.jianshu.com/p/f9acef0956b4

0 0
原创粉丝点击