iOS change navigation bar title font and color

后端 未结 18 794
青春惊慌失措
青春惊慌失措 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 08:58

    The correct way to change the title font (and color) is:

    [self.navigationController.navigationBar setTitleTextAttributes:
     @{NSForegroundColorAttributeName:[UIColor redColor],
    NSFontAttributeName:[UIFont fontWithName:@"mplus-1c-regular" size:21]}];
    

    Edit: Swift 4.2

    self.navigationController?.navigationBar.titleTextAttributes =
    [NSAttributedString.Key.foregroundColor: UIColor.red,
     NSAttributedString.Key.font: UIFont(name: "mplus-1c-regular", size: 21)!]
    

    Edit: Swift 4

    self.navigationController?.navigationBar.titleTextAttributes =
    [NSAttributedStringKey.foregroundColor: UIColor.red,
     NSAttributedStringKey.font: UIFont(name: "mplus-1c-regular", size: 21)!]
    

    Swift 3:

    self.navigationController?.navigationBar.titleTextAttributes = 
    [NSForegroundColorAttributeName: UIColor.redColor(),
     NSFontAttributeName: UIFont(name: "mplus-1c-regular", size: 21)!]
    

提交回复
热议问题