How can I set custom font in UINavigationBar?

前端 未结 2 1664
隐瞒了意图╮
隐瞒了意图╮ 2021-02-06 10:09

How can I set custom font in UINavigationBar ? I need the tahoma font.

- (void)viewDidLoad{
    self.title =@\"My text\";
}

2条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-06 10:44

    Totally possible, if a little tricky to do. Once you've found the font you need (either one of the alternatives already shipped with iOS, or a TTF file that you've got the correct licensing for), just create a UILabel with the size, formatting, font etc and then add it to the navigation items for that bar (or, if you're doing this in a view controller, set the .navigationItem.titleView of that controller to your label).

    For example, I have a view controller inside a UINavigationController. To change the label in the top to a custom font, I simply do:

    //...I have already setup a UILabel called navLabel that has the same style as a 
    // default navigation bar title, but I've changed the .font property to my custom font
    self.navigationItem.titleView = navLabel;
    [navLabel release];
    

提交回复
热议问题