如何更改工具栏按钮的颜色?
问题描述:
UIToolbar* tb = [[self navigationController] toolbar];
for (UIBarButtonItem * item in tb.items)
item.tintColor = [UIColor yellowColor];
改变tintcolor每一个按钮,但不能[[[self navigationController] toolbar] setTintColor:[UIColor yellowColor]] ;
有什么不对改变tintcolor所有按钮?
答
最简单的方法是使用UIAppearance
protocol。
某处在您的应用程序(我这样做是在应用程序委托)把东西滑过这个...
[[UITabBar appearance] setBarTintColor:[UIColor colorWithWhite:0.97 alpha:1]];
[[UITabBar appearance] setSelectedImageTintColor:[UIColor yellowColor]];
编辑
刚刚看到您使用UIToolBar
没有标签栏。所以,你可以做到这一点...
[[UIBarButtonItem appearanceWhenContainedIn:[UIToolBar class] set.....
您可以勾搭其他属性太喜欢...
// this uses an embedded font to set the font of tab items.
[[UITabBarItem appearance] setTitleTextAttributes:@{NSFontAttributeName: [UIFont bariolRegularFontOfSize:14]} forState:UIControlStateNormal];
你可以做同样的事情有标签,按钮,导航栏, etc ...