Coder Social home page Coder Social logo

bnrdynamictypemanager's Introduction

BNRDynamicTypeManager

Version Platform Build Status

BNRDynamicTypeManager is a collection of helper classes that make it easier to use Dynamic Type in iOS 7 applications. Most importantly, it handles listening for UIContentSizeCategoryDidChangeNotification and updating the fonts of all "watched" views automatically.

To run the example project, clone the repo, make sure the Example target is selected, and run it.

To run the unit tests, run pod install from the Tests directory first.

Usage - XIB Files and Storyboards

The simplest use case is if your are using XIB files or storyboards. After pulling BNRDynamicTypeManager into your project, change any instances of the following classes to the appropriate BNRDynamicTypeManager-provided subclasses (and make sure that one of the system Text Styles is selected as the view's font):

  • UILabelBNRDynamicTypeManagedLabel
  • UIButtonBNRDynamicTypeManagedButton
  • UITextFieldBNRDynamicTypeManagedTextField
  • UIViewBNRDynamicTypeManagedView

Usage - Programmatic View Creation

If you are creating views programmatically, use the same class mapping from Using XIB Files above, and use the designated initializer from their header files. The initializers have the same arguments as the UIKit parents with an additional textStyle: argument. For example, creating a managed UILabel and UITextView:

#include <BNRDynamicTypeManager/BNRDynamicTypeManagedLabel.h>
#include <BNRDynamicTypeManager/BNRDynamicTypeManagedButton.h>
#include <BNRDynamicTypeManager/BNRDynamicTypeManagedTextField.h>
#include <BNRDynamicTypeManager/BNRDynamicTypeManagedTextView.h>

UILabel *label = [[BNRDynamicTypeManagedLabel alloc]
                       initWithFrame:CGRectZero
                           textStyle:UIFontTextStyleBody];
UIButton *button = [[BNRDynamicTypeManagedButton alloc]
                         initWithFrame:CGRectZero
                             textStyle:UIFontTextStyleBody];
UITextField *textField = [[BNRDynamicTypeManagedTextField alloc]
                               initWithFrame:CGRectZero
                                   textStyle:UIFontTextStyleFootnote];
UITextView *textView = [[BNRDynamicTypeManagedTextView alloc]
                             initWithFrame:CGRectZero
                             textContainer:nil
                                 textStyle:UIFontTextStyleFootnote];

Usage - Without UIKit Subclasses

If you want more explicit control (e.g., if you already have a UIKit subclass that you're using, but you'd still like to have the font managed for you), use BNRDynamicTypeManager directly by telling it what objects to watch. If the object is one of the known UIKit classes or a subclass of them, use the provided methods. E.g., for UILabel:

#include <BNRDynamicTypeManager/BNRDynamicTypeManager.h>

UILabel *label = /* create a label */;

// Tell BNRDynamicTypeManager to update label.font now and any time the user
// changes their font size.
[[BNRDynamicTypeManager sharedInstance] watchLabel:label
                                         textStyle:UIFontTextStyleBody];

If you want to watch an object that isn't one of the known UIKit classes, but has a UIFont *font that can be reached via a keypath, use watchElement:fontKeypath:textStyle: instead. E.g., if there wasn't a method provided for UIButton:

#include <BNRDynamicTypeManager/BNRDynamicTypeManager.h>

UIButton *button = /* create a button */;

[[BNRDynamicTypeManager sharedInstance] watchElement:button
                                         fontKeypath:@"titleLabel.font"
                                           textStyle:UIFontTextStyleBody];

Requirements

iOS 7 and ARC.

Installation with Cocoapods

BNRDynamicTypeManager is available through CocoaPods, to install it simply add the following line to your Podfile:

pod "BNRDynamicTypeManager", "~> 0.1.0"

Installation without Cocoapods

Grab the class files (header and implementation) from the BNRDynamicTypeManager/Core and BNRDynamicTypeManager/Controls directory and copy them into your project.

Author

John Gallagher, [email protected]

License

BNRDynamicTypeManager is available under the MIT license. See the LICENSE file for more info.

bnrdynamictypemanager's People

Contributors

hydhknn avatar jgallagher avatar lyricsboy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  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.