简体   繁体   English

iOS-动态类型和界面生成器

[英]iOS - Dynamic Type and Interface Builder

Trying to implement support for Dynamic Type and have an issue. 尝试实现对动态类型的支持,并且遇到了问题。 I set the style I want to use on a label or something in Interface Builder. 我设置了要在标签或Interface Builder中使用的样式。 I register for the UIContentSizeCategoryDidChangeNotification, and in the handler, I set the label's font to ... what? 我注册了UIContentSizeCategoryDidChangeNotification,然后在处理程序中,将标签的字体设置为...什么? How do I know what style to use? 我如何知道要使用哪种样式? Shouldn't there be an accessor that lets me find that out? 是否应该有一个让我知道的访问器? If not, I have to put it in 2 places, which means they'll get out of sync and I'll be annoyed. 如果没有,我必须将其放在2个地方,这意味着它们将不同步,我会很烦。 Any thoughts? 有什么想法吗?

I don't think this will satisfy you, but set the font to [UIFont preferredFontForTextStyle:UIFontTextStyleTitle2 or whatever style you set in Interface Builder. 我认为这不会满足您的要求,但可以将字体设置为[UIFont preferredFontForTextStyle:UIFontTextStyleTitle2或您在Interface Builder中设置的任何样式。

Ignore the setting in Interface Builder. 忽略Interface Builder中的设置。 It's not even worth setting. 甚至都不值得设置。 Interface Builder is a (mostly) static representation of the initial state of your views, but this is Dynamic Type. Interface Builder是视图初始状态的(大部分) 静态表示,但这是动态类型。

You could subclass UILabel to make it dynamic, and/or join us on the dark side of setting up views in code. 您可以将UILabel子类化以使其动态化,和/或加入我们以在代码中设置视图的黑暗面。

Since iOS 10, there's no need to follow this rationale because the adjustsFontForContentSizeCategory property allows an automatic scaling of the font sizes according to the content type size selected in the settings. 从iOS 10开始,无需遵循此原理,因为adjustsFontForContentSizeCategory属性允许根据设置中选择的内容类型大小自动缩放字体大小。

All the text styles are well defined in the Apple reference site and their size variations as well. Apple参考站点中 ,所有文本样式均已明确定义,并且它们的大小也有所不同。

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

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