2014-08-27 56 views
0

我可以如何更改工具欄按鈕的顏色?

UIToolbar* tb = [[self navigationController] toolbar]; 
for (UIBarButtonItem * item in tb.items) 
     item.tintColor = [UIColor yellowColor]; 

改變tintcolor每一個按鈕,但不能[[[self navigationController] toolbar] setTintColor:[UIColor yellowColor]] ; 有什麼不對改變tintcolor所有按鈕?

回答

1

最簡單的方法是使用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 ...

相關問題