Giter Club home page Giter Club logo

customdynamictypefont's Introduction

Custom Fonts with Dynamic Type

One of the major shortcommings of Dynamic Type in iOS is the inability to use custom fonts.

To implement custom dynamic type for a project I wrote this code.

The app that currently uses this code in the store is availible here: www.appstore.com/QEDC.

Requirements

This will only work for iOS 7. I will test with iOS 8 as its release date approaches.

Installation

Cocoapods

Git Submodule

Manual

Clone this repository and drag UIFont+RSCustom.h/.m and customFont.plist to your project.

Usage

Adding Custom Fonts

Adding a Custom Font is a easy but an error can be hard to diagnose if done incorrectly.

Add Fonts to Target

Drag your font file to the project and make sure you add the font to the target Check Target Membership

Add Fonts to info.plist
Open up your App's info.plist
Add a new Array entry called "Fonts provided by Application"
Add each custom font filename to the array

Alt text

Defining Custom fonts in pList

You can specify which fonts you want to use for which category in a pList called customFonts. Below is a example.

Alt text

Code

After importing UIFont+RSCustom.h in the necessary file, you can assign a custom font to any font instance like this:

 self.labelBody.font = [UIFont customFontForTextStyle:UIFontTextStyleBody];

Unfortunately, this font will not automatically update if the user changes their preferred text size after you set the font. You need to observe for UIContentSizeCategoryDidChangeNotification in case this unlikely event occurs.

in viewDidLoad/WillAppear/DidAppear add

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

Then implement sizeChanged:

-(void) sizeChanged:(id) sender {

   self.labelBody.font = [UIFont customFontForTextStyle:UIFontTextStyleBody];

   // call invalidateIntrinsicContentSize if using Auto Layout
   [self.labelBody invalidateIntrinsicContentSize];
}

Feature Requests and Bug Fixes

Please open an issue for bugs and feature requests. I would prefer to to have a discussion about the bug/feature request and then we can discuss who will submit the pull request for the issue.

iOS 8 and XCode 6

I will be watching out for updates to XCode 6 and Interface Builder to render the fonts at the right time.

License

MIT License

customdynamictypefont's People

Contributors

vrao423 avatar zoejessica avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.