Search code examples
iosios6

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.


Solution

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

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