Latest 0.2.5
Homepage https://github.com/kgn/KGNPreferredFontManager
License MIT
Platforms ios 8.0, requires ARC
Frameworks UIKit
Authors

Helper class to registering custom fonts for UIFontTextStyle.

[iOS 8.0+]()
[Xcode 7.1]()
[Swift 2.0]()
Release
Build Status

Build Status
[Test Coverage]()
Carthage Compatible
CocoaPods Version
CocoaPods Platforms

Twitter
Star
Star

iOS 7 introduced the concept of dynamic fonts for accessibility and readability. This library makes it easy to implement these features to help make your app more accessible and readable.

This library also helps keep the fonts in your app consistent by setting a strict set of fonts to use based on the text styles introduced in iOS 7.

Subclasses of UILabel and UIButton are also provided that work with these text styles and the KGNPreferredFontManager to automatically update and resize to the appropriate font size for the user’s text size and accessibility settings. It is recommended that KGNAutoLayout be used in conjunction with this library so that elements resize and adjust appropriately as font sizes change.

Example Gif

Installing

Carthage

github "kgn/KGNPreferredFontManager"

CocoaPods

pod 'KGNPreferredFontManager'

Examples

PreferredFontManager

Create a PreferredFontManager to specify the font sizes to be used when the user changes their accessibility settings.

The following code registers each of the standard text styles with a fontWeight and baseFontSize. This base font size is used for the UIContentSizeCategoryLarge font size and then incremented and decremented by the amounts passed to the increment and decrement properties.

There is an additional property that defines if the incrementing should extend into the extra accessibility size categories. This includeAccessibilitySizes argument is false by default, but is often useful to make sure body text is extra large, like in Messages.app.

There are two versions of this method. One takes fontWeight: CGFloat, which is a UIFontWeight... constant introduced in iOS 8.2. The other takes fontName: String which is a the name of the font, either a system one or a custom one.

fontWeight(iOS 8.2+)

Check out the Example app provided to see this in action.

PreferredFontManager.sharedManager().registerFontsForTextStyle(UIFontTextStyleHeadline, fontWeight: UIFontWeightUltraLight, baseFontSize: UIFont.systemFontSize()*4, increment: 1, decrement: 1)
PreferredFontManager.sharedManager().registerFontsForTextStyle(UIFontTextStyleSubheadline, fontWeight: UIFontWeightRegular, baseFontSize: UIFont.systemFontSize()*2, increment: 1, decrement: 1)
PreferredFontManager.sharedManager().registerFontsForTextStyle(UIFontTextStyleBody, fontWeight: UIFontWeightRegular, baseFontSize: UIFont.labelFontSize(), increment: 2, decrement: 1, includeAccessibilitySizes: true)
PreferredFontManager.sharedManager().registerFontsForTextStyle(UIFontTextStyleCaption1, fontWeight: UIFontWeightMedium, baseFontSize: UIFont.systemFontSize(), increment: 1, decrement: 1)
PreferredFontManager.sharedManager().registerFontsForTextStyle(UIFontTextStyleCaption2, fontWeight: UIFontWeightRegular, baseFontSize: UIFont.systemFontSize(), increment: 1, decrement: 1)
PreferredFontManager.sharedManager().registerFontsForTextStyle(UIFontTextStyleFootnote, fontWeight: UIFontWeightRegular, baseFontSize: UIFont.smallSystemFontSize(), increment: 1, decrement: 1)

fontName

PreferredFontManager.sharedManager().registerFontsForTextStyle(UIFontTextStyleHeadline, fontName: "AvenirNext-Light", baseFontSize: 28, increment: 2, decrement: 2)
PreferredFontManager.sharedManager().registerFontsForTextStyle(UIFontTextStyleSubheadline, fontName: "AvenirNext-Regular", baseFontSize: 22, increment: 2, decrement: 1)
PreferredFontManager.sharedManager().registerFontsForTextStyle(UIFontTextStyleBody, fontName: "AvenirNext-Regular", baseFontSize: 17, increment: 1, decrement: 1, includeAccessibilitySizes: true)
PreferredFontManager.sharedManager().registerFontsForTextStyle(UIFontTextStyleCaption1, fontName: "AvenirNext-Medium", baseFontSize: 15, increment: 1, decrement: 1)
PreferredFontManager.sharedManager().registerFontsForTextStyle(UIFontTextStyleCaption2, fontName: "AvenirNext-Regular", baseFontSize: 13, increment: 1, decrement: 1)
PreferredFontManager.sharedManager().registerFontsForTextStyle(UIFontTextStyleFootnote, fontName: "AvenirNext-Regular", baseFontSize: 11, increment: 1, decrement: 1)

PreferredFontButton, PreferredFontLabel & PreferredFontTextField

PreferredFontButton, PreferredFontLabel and PreferredFontTextField are subclasses of UIButton, UILabel and UITextFieldrespectively but they incorporate a PreferredFontManager and subscribe to UIContentSizeCategoryDidChangeNotification so the font used it automatically updated for the selected accessibility font size selected buy the user.

let label = PreferredFontLabel()
let button = PreferredFontButton()
let textField = PreferredFontTextField()

Property: textStyle

By default the UIFontTextStyleBody is used, but this can be customized and changed at any time with the textStyle: initializer or the .textStyle property.

let label = PreferredFontLabel(textStyle: UIFontTextStyleHeadline)
let button = PreferredFontButton(textStyle: UIFontTextStyleHeadline)
let textField = PreferredFontTextField(textStyle: UIFontTextStyleHeadline)

Property: preferredFontManager

By default this property is set to PreferredFontManager.sharedManager(), if there is not a registered text style UIFont.preferredFontForTextStyle is used instead. This property can also be set to a custom PreferredFontManager object.

Progress:

  • [X] Tests
  • [X] Travis
  • [X] Badges
  • [X] Carthage
  • [X] CocoaPods
  • [X] Description
  • [X] Documentation

Latest podspec

{
    "name": "KGNPreferredFontManager",
    "version": "0.2.5",
    "authors": {
        "David Keegan": "[email protected]"
    },
    "homepage": "https://github.com/kgn/KGNPreferredFontManager",
    "summary": "Helper class to registering custom fonts for UIFontTextStyle",
    "source": {
        "git": "https://github.com/kgn/KGNPreferredFontManager.git",
        "tag": "v0.2.5"
    },
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "platforms": {
        "ios": "8.0"
    },
    "requires_arc": true,
    "frameworks": "UIKit",
    "source_files": "Source/PreferredFont*.swift"
}

Pin It on Pinterest

Share This