可以在IB的导航栏中自定义提示字符串的字体吗? [英] Possible to customize font of prompt string in nav bar on IB?

查看:32
本文介绍了可以在IB的导航栏中自定义提示字符串的字体吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以自定义提示字符串?

Is it possible to customize the prompt string at all?

我已将 navigationBarItem 连接到我的 ViewController 并添加了一个字符串作为Prompt".通过IB.提示类之后没有允许我更改字符串、颜色等内容的属性.我想知道是否有人知道解决此问题的任何其他可能的方法?

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?

推荐答案

可以自定义提示外观,但有一个很大的限制,提示和标题的样式将始终相同.

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.

假设您在带有导航栏的导航控制器中呈现的 UIViewController 中,您可以这样做:

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]

您还可以使用 UINavigationBar.appearance() 方法在应用中的所有导航栏提示上进行此配置.

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

这篇关于可以在IB的导航栏中自定义提示字符串的字体吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆