IOS 杂笔-13(appearance的巧妙使用)

在我们查看原生api时,我们不难发现,有些api的后面有着->UI_APPEARANCE_SELECTOR

那么我可以很高兴的说我们可以通过appearance对象来统一设置。十分巧妙。

例如:

我们可以通过如下方法对对象进行统一设置,从而提高编码效率。

NSDictionary * attrs = @{
                             
                             NSFontAttributeName:[UIFont systemFontOfSize:13],
                             NSForegroundColorAttributeName:[UIColor grayColor]
                             
                             };
    
    NSDictionary * selectAttrs = @{
                                   
                                   NSFontAttributeName:[UIFont systemFontOfSize:12],
                                   NSForegroundColorAttributeName:[UIColor darkGrayColor]
                                   
                                   };
    
    UITabBarItem * item = [UITabBarItem appearance];
    [item setTitleTextAttributes:attrs forState:UIControlStateNormal];
    [item setTitleTextAttributes:selectAttrs forState:UIControlStateSelected];
原文地址:https://www.cnblogs.com/xubaoaichiyu/p/5321644.html