简体   繁体   English

如何根据 navigationItem.title 的设备大小调整字体大小

[英]how do i adjust font size depending on device size of navigationItem.title

I have a chat screen in my app where in recent iPhone the navigation title looks ok.我的应用程序中有一个聊天屏幕,在最近的 iPhone 中,导航标题看起来不错。 but on an older devices like 6/7/8 the font is too big, I know.adjustsFontSizeToFitWidth = true and.minimumScaleFactor = 0.2 can adjust the font size of uilabel but how do I do the same for navigationItem.title, adding varient to storyboard for (C,C) didn't solve the problem但是在像 6/7/8 这样的旧设备上,字体太大了,我知道。adjustsFontSizeToFitWidth = true and.minimumScaleFactor = 0.2 可以调整 uilabel 的字体大小,但是我如何对 navigationItem.title 做同样的事情,将变量添加到storyboard for (C,C) 没有解决问题

navigation item actually has a property called titleView which you can set your custom label to导航项实际上有一个名为 titleView 的属性,您可以将自定义 label 设置为

Example:例子:

let myLabel = UILabel()

myLabel.text = "Custom Title"
myLabel.minimumScaleFactor = 0.2
myLabel.numberOfLines = 1
myLabel.adjustsFontSizeToFitWidth = true
myLabel.font = UIFont.preferredFont(forTextStyle: .title1)

navigationItem.titleView = myLabel

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM