iOS change navigation bar title font and color

后端 未结 18 778
青春惊慌失措
青春惊慌失措 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

    Don't forget to add the Raw values of the keys to avoid compile errors.

        let textAttributes:[NSAttributedStringKey: Any] = [NSAttributedStringKey(rawValue: NSAttributedStringKey.foregroundColor.rawValue):UIColor.blue, NSAttributedStringKey(rawValue: NSAttributedStringKey.font.rawValue):UIFont(name:"OpenSans", size: 17)!]
        navigationController?.navigationBar.titleTextAttributes = textAttributes
    

提交回复
热议问题