SSDynamicText 1.1.1

SSDynamicText 1.1.1

LangLanguage Obj-CObjective C
License MIT
ReleasedLast Release Jan 2017

Maintained by Jonathan Hersh, Samuel Giddins.

Circle CI

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

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.


Xcode 7.0+ with iOS 7.0+ SDK.

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 *myLabel = [SSDynamicLabel labelWithFont:@"Courier"
myLabel.text = @"Auto-sizing text!";

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


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


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


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


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

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


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;


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