如何在iOS 7中支持标签中的动态类型? [英] How to support dynamic type in labels in iOS 7?

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

问题描述

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

解决方案

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



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



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



完成后,你应该听 UIContentSizeCategoryDidChangeNotification 。当您收到此通知时,您应该布置标签以支持新选择的大小(如果您使用自动布局,这通常就像向您的视图发送 invalidateIntrinsicContentSize 一样简单。)如果您正在寻找官方文档,请查看文本编程指南


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.

解决方案

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天全站免登陆