问题
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