Tuesday, December 10, 2013

How to Support Dynamic Type in iOS 7 Apps


Dynamic Type, is a feature added to iOS 7, that gives users the ability to choose a base text size. This text size will be used throughout the device including third-party applications. Here we discuss on How to Support Dynamic Type in iOS 7 Apps by working on a sample iOS app.

Step 1 - Create a View based iOS application.

Step 2 - Add a UILabel to the ViewController via story board and set the label outlet as contentLabel and add some text on it.

Step 3 - Goto ViewController.m and add the following code inside viewdidload.  This code will listen to the notification if text size is changed in the settings of the device.

  [[NSNotificationCenter defaultCenter]  
    addObserver:self  
    selector:@selector(changeTextSize:)  
    name:UIContentSizeCategoryDidChangeNotification  
    object:nil];  

Step 4 - Add the following function just below viewdidload.
- (void)changeTextSize:(NSNotification *)notification {  
   self.contentLabel.font = [UIFont preferredFontForTextStyle:UIFontTextStyleBody];  
 }  

Step 5 - You can test the feature by changing the Text Size. For that goto Settings App -> General -> Text Size and change the slider value. Come back to your app and check the font size of text in contentLabel .

Done :)

No comments:

Post a Comment