How to change the text color on UINavigationBar button items

前端 未结 8 1609
梦如初夏
梦如初夏 2020-12-24 00:12

I\'ve got a UINavigationController and i\'ve changed it to white using the Tint property of the navigation bar in Interface Builder. But the text in buttons and the title is

相关标签:
8条回答
  • 2020-12-24 00:50

    I did as drunknbass suggested. I resorted to making a series of images for back-button in a few states, and regular buttons in a few states, and put them in a custom UIButton subclass, setting up the appropriate styles.

    As a solution it doesn't scale particularly well, but my needs were simple enough. It has the advantage of not breaking if the subview orders in the built in controls change though, which is the obvious downside of that approach. Disadvantage of needing several images. The other tricky thing is handling an orientation change, since the buttons should change size.

    On a related note, if you do change the tint color of your navigation bar, it does not play well with the special "More" view controller for customizing the order of a tab bar. There doesn't seem to be any "acceptable" way to change the color of the toolbar in that view.

    0 讨论(0)
  • 2020-12-24 00:52

    As of iOS 5 this it much easier, using the UIBarButtonItem appearance proxy:

     NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys: 
                            [UIColor blackColor], 
                            UITextAttributeTextColor, 
                            [UIColor clearColor], 
                            UITextAttributeTextShadowColor, nil];
    
    [[UIBarButtonItem appearance] setTitleTextAttributes: attributes
                                                forState: UIControlStateNormal];
    

    Set this in application:didFinishLaunchingWithOptions:

    0 讨论(0)
提交回复
热议问题