我的导航栏的大标题太宽了。如何解决? [英] My navigation bar's large title is too wide. How to fix that?

查看:802
本文介绍了我的导航栏的大标题太宽了。如何解决?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用导航控制器,我设置为true导航栏的 prefersLargeTitle 属性。一切都很好,但是当我的标题文字变得太大时,它就不适合空间。在这里看起来如何:

I am using navigation controller, and I've set to true its navigation bar's prefersLargeTitle property. Everything works fine, but when the text of my title becomes too big, it doesn't fit in space. Here how it looks:

是否有可能以某种方式使标题(导航栏的 prefersLargeTitle 属性设置为true)动态调整其字体大小,如果是这样,如何实现?

Is it possible to somehow make the title (while the navigation bar's prefersLargeTitle property is set to true) dynamically adjust its font size, and if it is so, how to achieve that?

推荐答案

这个问题在这里有所回答:如何动态调整导航栏中的标题大小

This question is somewhat answered here: How to resize Title in a navigation bar dynamically.

self.title = "Your TiTle Text"
let tlabel = UILabel(frame: CGRectMake(0, 0, 200, 40))
tlabel.text = self.title
tlabel.textColor = UIColor.whiteColor()
tlabel.font = UIFont(name: "Helvetica-Bold", size: 30.0)
tlabel.backgroundColor = UIColor.clearColor()
tlabel.adjustsFontSizeToFitWidth = true
self.navigationItem.titleView = tlabel

话虽如此,但略有不同,因为你设置了prefersLargeTitle属性。
现在,我不确定 tlabel.adjustsFontSizeToFitWidth = true 是否会覆盖 prefersLargeTitle 属性,但请尝试它出去看看它是否有效。此处还有一些关于导航项目大型标题的其他信息: https:// developer .apple.com /文档/ UIKit的/ uinavigationitem / 2909056-largetitledisplaymode 。希望这会有所帮助。

That being said, this is slightly different, in that you have the prefersLargeTitle property set. Now, I am not sure whether the tlabel.adjustsFontSizeToFitWidth = true overrides the prefersLargeTitle property, but try it out and see if it works. There is also some additional information regarding navigation item large titles here: https://developer.apple.com/documentation/uikit/uinavigationitem/2909056-largetitledisplaymode. Hope this helps.

这篇关于我的导航栏的大标题太宽了。如何解决?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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