UIBarButtonItem关于全局修改,局部修改

工具类UIAppearance可以统一设置控件的风格,当调用appearance方法时他会拿到相对应的控件(你用什么控件调用appearace方法,他就会返回什么控件),然后你可以设置统一主题(风格)

+ (id)appearance
+ (id)appearanceWhenContainedIn:(Class <>)ContainerClass,...
 
第一个方法是统一全部改,比如你设置UINavigationBar 的tintColor,你可以这样写:
[[UINavigationBar appearance] setTintColor:myColor];

/** 这样写之后,所有的 UINavigationBar 的tintColor的颜色都为myColor */

第二个方法是当出现在某个类的出现时候才会改变

[[UIBarButtonItem appearanceWhenContainedIn:[UINavigationBar class], [UIPopoverController class], nil] setTintColor:myPopoverNavBarColor];

1.修改背景: 
[[UIBarButtonItem appearance] setBackButtonBackgroundImage:leftButton  
                                                      forState:0  
                                                    barMetrics:UIBarMetricsDefault];  
 

2.修改字体,阴影,字体颜色
NSDictionary* textAttributes = [NSDictionary dictionaryWithObjectsAndKeys:  
                                   BAR_BUTTON_TITLE_TEXT_COLOR,UITextAttributeTextColor,  
                                   BAR_BUTTON_TITLE_FONT,UITextAttributeFont,  
                                   BAR_BUTTON_TITLE_SHADOW_COLOR,UITextAttributeTextShadowColor,  
                                   [NSValue valueWithCGSize:CGSizeMake(1, 1)],UITextAttributeTextShadowOffset,  
                                   nil];  
  
   [[UIBarButtonItem appearance] setTitleTextAttributes:textAttributes forState:0];  

3,修改UIBarButtonItem中文字的位置:
[[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(2, -1)  
                                                       forBarMetrics:UIBarMetricsDefault];  
原文地址:https://www.cnblogs.com/wangliang2015/p/5626420.html