How to change the text color on UINavigationBar button items

前端 未结 8 1692
梦如初夏
梦如初夏 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:46

    Here's one way:

    [[theNavigationBar.subviews objectAtIndex:1] setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    [[theNavigationBar.subviews objectAtIndex:2] setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    

    However, HUGE, caveat. This is highly likely to break on a future OS release and is not recommended.

    At the very least you should perform a lot of testing and make sure you your assumptions of the subview layout of the navigation bar are correct.

提交回复
热议问题