Possible to customize font of prompt string in nav bar on IB?

若如初见. 提交于 2019-12-12 04:11:58

问题


Is it possible to customize the prompt string at all?

I have hooked up the navigationBarItem to my ViewController and added a string as the "Prompt" via IB. There are no properties following the prompt class that allow me to alter the contents of the string, color, etc etc. I was wondering if anyone knows any other possible work around for this problem?


回答1:


It is possible to customize the prompt appearance with one big limitation, the style of the prompt and of the title will always be the same.

Assuming you are in a UIViewController presented within a navigation controller with a navigation bar, you can do this:

guard let font = UIFont(name: "Helvetica", size: 17) else {
   return
}

let navigationBar = navigationController?.navigationBar
navigationBar?.titleTextAttributes = [NSFontAttributeName: font,
                                                            NSForegroundColorAttributeName: UIColor.blue]

You can also use the UINavigationBar.appearance() method to have this configuration on all the navigation bar prompts in your app.



来源:https://stackoverflow.com/questions/45516831/possible-to-customize-font-of-prompt-string-in-nav-bar-on-ib

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!