码迷,mamicode.com
首页 > 移动开发 > 详细

[转]Appearance

时间:2016-07-08 23:22:00      阅读:253      评论:0      收藏:0      [点我收藏+]

标签:

Appearance Proxies

UIAppearance是一个协议,UIView默认已经遵守了这个协议。

@protocol UIAppearance <NSObject>
@interface UIView : UIResponder <NSCoding, UIAppearance, UIAppearanceContainer, UIDynamicItem, UITraitEnvironment, UICoordinateSpace, UIFocusEnvironment>

来看看UIAppearance都有什么方法

+ (instancetype)appearance;
+ (instancetype)appearanceWhenContainedIn:(nullable Class <UIAppearanceContainer>)ContainerClass, ... NS_REQUIRES_NIL_TERMINATION NS_DEPRECATED_IOS(5_0, 9_0, "Use +appearanceWhenContainedInInstancesOfClasses: instead") __TVOS_PROHIBITED;
+ (instancetype)appearanceWhenContainedInInstancesOfClasses:(NSArray<Class <UIAppearanceContainer>> *)containerTypes NS_AVAILABLE_IOS(9_0);
+ (instancetype)appearanceForTraitCollection:(UITraitCollection *)trait NS_AVAILABLE_IOS(8_0);
+ (instancetype)appearanceForTraitCollection:(UITraitCollection *)trait whenContainedIn:(nullable Class <UIAppearanceContainer>)ContainerClass, ... NS_REQUIRES_NIL_TERMINATION NS_DEPRECATED_IOS(8_0, 9_0, "Use +appearanceForTraitCollection:whenContainedInInstancesOfClasses: instead") __TVOS_PROHIBITED;
+ (instancetype)appearanceForTraitCollection:(UITraitCollection *)trait whenContainedInInstancesOfClasses:(NSArray<Class <UIAppearanceContainer>> *)containerTypes  NS_AVAILABLE_IOS(9_0);

让某一类控件同时表现某种属性

[[UIButton appearance] setBackgroundColor:[UIColor blackColor]];
[[UIButton appearance] setTitle:@"呵呵哒" forState:UIControlStateNormal];

让某一类控件在另一种控件中同时变现某种属性

[[UIButton appearanceWhenContainedInInstancesOfClasses:@[[UIView class]]] setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];

上面这句话的意思 就是----使UIView上面的UIButton的titleColor都变成灰色的
效果的话大家可以自己试试,我这里不知道怎么贴图片。。。。。



文/Luxlight(简书作者)
原文链接:http://www.jianshu.com/p/1e4745f0f163
著作权归作者所有,转载请联系作者获得授权,并标注“简书作者”。
 
 
自己在模仿 传智微博时的代码
 

 

@interface JXTabBarController ()

 

@end

 

@implementation JXTabBarController

+ (void)initialize

{

    [[UITabBarItem appearanceWhenContainedInInstancesOfClasses:@[[self class]]] setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor orangeColor]} forState:UIControlStateSelected];

    

}

 
 
 
 
 
 
 
 
 
 

[转]Appearance

标签:

原文地址:http://www.cnblogs.com/T15053781465/p/5654772.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!