How to change the text color on UINavigationBar button items

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

    Here the clean way (relying on public API) to do this IMHO : you should use the titleView property of the navigationItem to apply it your own UILabel on which you will customize the textColor

    
    UILabel* lbl = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 320, 20)];
    lbl.textAlignment=UITextAlignmentCenter;
    lbl.backgroundColor=[UIColor clearColor];
    lbl.textColor=[UIColor colorWithRed:0.18 green:0.2 blue:0.56 alpha:1];
    theControllerOnWhichYouWantToHaveATitleWithYourOwnColor.navigationItem.titleView=lbl;
    [lbl release];
    
    

提交回复
热议问题