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 :)

2 comments:

  1. hi..Im college student, thanks for sharing :)

    ReplyDelete
  2. Nice blogs.
    Videocon and stay in touch with your Contacts, Friends, and Loved ones.
    Seamless Roaming across India. National Roaming is Pre-Activated on Videocon Prepaid Connection with Zero Monthly Rentals.
    Tariff while Roaming anywhere in India.

    ReplyDelete