简体   繁体   中英

How to change toolbar buttons color?

I can change tintcolor every button by

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

But can not change tintcolor all buttons by [[[self navigationController] toolbar] setTintColor:[UIColor yellowColor]] ; What's wrong?

The easiest way to do this is with the UIAppearance protocol .

Somewhere in your app (I do this in the app delegate) put something glide this...

[[UITabBar appearance] setBarTintColor:[UIColor colorWithWhite:0.97 alpha:1]];
[[UITabBar appearance] setSelectedImageTintColor:[UIColor yellowColor]];

EDIT

Just saw that you're using UIToolBar not Tab Bar. So you can do this...

[[UIBarButtonItem appearanceWhenContainedIn:[UIToolBar class] set.....

You can mess around with other properties too like...

// this uses an embedded font to set the font of tab items.
[[UITabBarItem appearance] setTitleTextAttributes:@{NSFontAttributeName: [UIFont bariolRegularFontOfSize:14]} forState:UIControlStateNormal];

You can do the same sort of thing with labels, buttons, navigation bars, etc...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM