UIAppearence Protocol

来源:互联网 发布:网络侵权管辖最新规定 编辑:程序博客网 时间:2024/06/06 18:40

      • appearance
      • UI_APPEARANCE_SELECTOR

appearance

+ (instancetype)appearance;

该属性能够定制一个类的事例的外观.发送和外观(appearence)相关的消息给这个类的appearence代理.
例如去修改UINavigationBar实例的bar的tint color可以用下面的代码:

[[UINavigationBar appearance] setBarTintColor:myColor];

在iOS7,tintColor这个属性移到了UIView,并且继承了一些特殊的行为.
继承的行为会与appearance代理产生冲突,所以tintColor不再允许在appearance代理中了.

UI_APPEARANCE_SELECTOR

UI_APPEARANCE_SELECTOR的定义:

#define UI_APPEARANCE_SELECTOR __attribute__((annotate("ui_appearance_selector")))

可以看出这时一个宏.
作为appearance 代理API的一部分,在header中用来标记外观属性的selector,
例如:

 - (void)setProperty:(PropertyType)property forAxis1:(IntegerType)axis1 axis2:(IntegerType)axis2 axisN:(IntegerType)axisN; - (PropertyType)propertyForAxis1:(IntegerType)axis1 axis2:(IntegerType)axis2 axisN:(IntegerType)axisN;

这里的PropertyType可以是iOS中的任何标准类型: id, NSInteger, NSUInteger, CGFloat, CGPoint, CGSize, CGRect, UIEdgeInsets or UIOffset.

IntegerType必须要么是NSInteger或NSUInteger;
如果不是的话,那么会抛出异常的.

所有内容摘自UIAppearance.h文件中.

原创粉丝点击