Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to support dynamic type in labels in iOS 7?

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.

like image 246
jaytrixz Avatar asked Sep 30 '13 10:09

jaytrixz


People also ask

How do you make text dynamic on Iphone?

Dynamic Type is a feature that enables the app's content to scale based on the user's preferred content size. The preferred content size can be found in Settings -> Accessibility -> Display & Text Size -> Larger Text.

What is dynamic typing in iOS?

Dynamic Type is a feature that was introduced in iOS 7 allowing users to change the default font size used across iOS. It is intended predominantly to support visually impaired users but in practice there are many iOS users who simply prefer a smaller / larger reading size for a variety of reasons.

How do you support dynamic type?

To add support for Dynamic Type in your app, you use text styles. A text style describes the use of the text, such as headline or body or title1 , and lets the system know how best to adjust its size. You can configure text styles in either Interface Builder or your source code.

Does Safari support dynamic type?

Fortunately, Safari's UIWebView (what Safari uses to display Web pages) handles this communication for you, but you have to do some work up front in your Web page. iOS has a feature called Dynamic Type (introduced in iOS 7) which communicates to applications what the user's preferred text size is.


1 Answers

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.

like image 75
lxt Avatar answered Oct 22 '22 08:10

lxt