首页 > 其他 > 详细

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

时间:2016-06-29 13:23:53      阅读:114      评论:0      收藏:0      [点我收藏+]

工具类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];  

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

原文:http://www.cnblogs.com/wangliang2015/p/5626420.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!