iOS change navigation bar title font and color

后端 未结 18 729
青春惊慌失措
青春惊慌失措 2020-12-04 08:40

So i have this code that should change the nav bar title font, but it doenst

    NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:[UIFon         


        
18条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-04 09:10

    I had one problem because when I tried to change my NavigationItem title programmatically i was not able to find my family font (tried many things but impossible to make it run correctly) so I found one workaround very nice and easy in storyboard.

    1. Firstly you add under Navigation Item one view in middle and don't forget to set backGroundColor to clear color to have the same color of navBar:

    1. Then you add one Label which you can edit (set color of text, font, size...) in this view
    2. You add constraints to label (Top = 0, Bottom = 0, Trailing = 0 and Leading = 0) to View and center text of label

    Finally you should have something like that in document outline:

    And something like that in your ViewController:

    Hope it can help.

提交回复
热议问题