简体   繁体   中英

change text color of Bar Button Item from storyboard

I have dragged and dropped Bar Button Item in Storyboard over navigation bar created by storyboard.
I would like to know how to change text color of Bar Button Item from storyboard ?
I have tried creating an outlet for bar button item then tried :
[myBackButton.titleLabel.textColor = [UIColor blackColor]];

even tried barbuttonItem :

[myButton setTitleColor:[UIColor redColor] forState:UIControlStateNormal]; 

but I am getting an error . I tried changing tint the background color changes but the text color is still white How do I Change the text color to black? Thanks in Advance.

You can change the text color using Attributes . For instance,

NSDictionary *attributes = @{UITextAttributeTextColor : [UIColor redcolor]};
[myButton setTitleTextAttributes:attributes
                      forState:UIControlStateNormal];

我认为这会有所帮助

[[UIBarButtonItem appearance] setTintColor:[UIColor yellowColor]];

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