如何支持iOS 7中的动态类型标签 [英] How to Support Dynamic Type in Labels in iOS 7

查看:126
本文介绍了如何支持iOS 7中的动态类型标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在iOS 7中支持 UILabel UITextView 中的动态类型?我正在调整我们的iOS 7项目之一,并希望支持此辅助功能。我在苹果的iOS开发者网站上找不到具体的教程。

解决方案

如果您使用新的 UIFont 方法然后你几乎在那里 - 你只需要添加观察者来监听更改。



而不是设置一个特定的字体大小,你应该使用在标注标签时,您可以使用 preferredFontForTextStyle:和相关方法(如果您正在使用Interface Builder,则可以直接在检查器中选择样式)。例如:



self.label.font = [UIFont preferredFontForTextStyle:UIFontTextStyleHeadline];



完成之后,您应该收听 UIContentSizeCategoryDidChangeNotification 。当您收到此通知时,您应该布局您的标签以支持新选择的大小(如果您使用的是自动布局,则通常会将 invalidateIntrinsicContentSize 发送到您的视图)。 / p>

如果您正在寻找官方文档,请查看文本编程指南


How do I support Dynamic Type in UILabel and UITextView in iOS 7? I'm adapting one of our projects for iOS 7 and would like to support this accessibility feature. I can't find the specific how to tutorial on it on Apple's iOS Developer site. Any links or sample code would be appreciated.

解决方案

If you use the new UIFont methods then you're pretty much there - you just need to add the observer to listen for changes.

Rather than setting a specific font size, you should use the preferredFontForTextStyle: and related methods when styling your labels (if you're using Interface Builder you can select a style directly in the inspector). For example:

self.label.font = [UIFont preferredFontForTextStyle:UIFontTextStyleHeadline];

Once you've done that you should listen for the UIContentSizeCategoryDidChangeNotification. When you receive this notification you should layout your labels to support the newly selected size (if you're using autolayout this is normally as simple as sending invalidateIntrinsicContentSize to your views).

If you're looking for official documentation then take a look at the Text Programming Guide.

这篇关于如何支持iOS 7中的动态类型标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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