Latest 1.1.1
Homepage https://github.com/splinesoft/SSDynamicText
License MIT
Platforms ios 7.0, requires ARC
Frameworks UIKit
Authors

Circle CI codecov.io
Version
Carthage compatible

iOS 7’s UIFontDescriptor is pretty neat. Also pretty neat is dynamic text that responds to the preferred text size that the user specified in Settings.app.

What’s not so neat, though, is that +[UIFont preferredFontForTextStyle:] only works with the system font, Helvetica Neue (iOS 8) or San Francisco (iOS 9). What if you have custom fonts and want to respect the user’s text size preference?

SSDynamicText is a collection of simple UILabel, UIButton, UITextField, and UITextView subclasses inspired by this SO answer.

Requirements

Xcode 7.0+ with iOS 7.0+ SDK.

Install

CocoaPods

Add to your Podfile:

pod 'SSDynamicText', '~> 1.1.1'

Carthage

Add to your Cartfile:

github "splinesoft/SSDynamicText", ~> 1.1.1

Example usage

SSDynamicText provides dynamic auto-sizing labels, buttons, text fields, and text views that respond when the user changes her preferred text size. Check out a full example.

UIKit views that responds when the user changes her preferred text size:

SSDynamicLabel

SSDynamicLabel *myLabel = [SSDynamicLabel labelWithFont:@"Courier"
                                               baseSize:16.0f];
myLabel.text = @"Auto-sizing text!";

// Already have a font descriptor?
UIFontDescriptor *aDescriptor = [UIFontDescriptor fontDescriptorWithName:@"Courier"
                                                                    size:16.0f];
SSDynamicLabel *otherLabel = [SSDynamicLabel labelWithFontDescriptor:aDescriptor];

SSDynamicButton

SSDynamicButton *myButton = [SSDynamicButton buttonWithFont:@"Courier"
                                                   baseSize:16.0f];
[myButton setText:@"Auto-sizing text!" forControlState:UIControlStateNormal];

SSDynamicTextField

SSDynamicTextField *myTextField = [SSDynamicTextField textFieldWithFont:@"Courier"
                                                               baseSize:16.0f];
myTextField.text = @"Auto-sizing text!";

SSDynamicTextView

SSDynamicTextView *myTextView = [SSDynamicTextView textViewWithFont:@"Courier"
                                                           baseSize:16.0f];
myTextView.text = @"Auto-sizing text!";

UIFont+SSTextSize

Create a UIFont object using the specified font name and base size.
The actual size of the returned font is adjusted by the user’s current preferred font size (specified in Settings.app).

UIFont *myFont = [UIFont dynamicFontWithName:@"Courier" baseSize:16.0f];

UIApplication+SSTextSize

This property returns a numeric delta between the default size setting (Large) and the user’s current preferred text size.

You probably don’t need to use this directly.

NSInteger textDelta = [[UIApplication sharedApplication] preferredFontSizeDelta];

NSAttributedString Support

SSDynamicText supports attributed text! Assign your NSAttributedString to the new dynamicAttributedText property.

UITextView and UITextField sometimes internally call -setAttributedText: even with normal text. To best accommodate that internal implementation detail, we’ve added a new dynamicAttribtuedText property instead of overriding -setAttributedText:.

@property (nonatomic, copy) NSAttributedString *dynamicAttributedText;

Thanks!

SSDynamicText is a @jhersh production — (electronic mail | @jhersh)

Latest podspec

{
    "name": "SSDynamicText",
    "version": "1.1.1",
    "summary": "UILabel/UIButton/UITextField/UITextView subclasses that support custom fonts with iOS 7's dynamic text sizes.",
    "homepage": "https://github.com/splinesoft/SSDynamicText",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Jonathan Hersh": "[email protected]"
    },
    "source": {
        "git": "https://github.com/splinesoft/SSDynamicText.git",
        "tag": "1.1.1"
    },
    "requires_arc": true,
    "compiler_flags": "-fmodules",
    "source_files": "SSDynamicText/*.{h,m}",
    "frameworks": "UIKit",
    "platforms": {
        "ios": "7.0"
    },
    "social_media_url": "https://twitter.com/jhersh"
}

Pin It on Pinterest

Share This