Skip to content

splinesoft/SSDynamicText

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SSDynamicText

Circle CI codecov.io

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. What if you have custom fonts and want to respect the user's text size preference?

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

Install

Install with CocoaPods. Add to your Podfile:

pod 'SSDynamicText', :head # YOLO

SSDynamicLabel

A label that responds when the user changes her preferred text size. Check out Example for a full example.

/**
 * Create a dynamic auto-sizing label using a custom font and a base font size.
 * The font size will be adjusted up (or down) based on the user's preferred size.
 * If the user leaves the app, switches to Settings, and changes preferred size,
 * the label will automatically update its size when the app returns to foreground.
 */
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];

SSDynamicTextField

A text field that responds when the user changes her preferred text size. Check out Example for a full example.

/**
 * Create a dynamic auto-sizing text field using a custom font and a base font size.
 * The font size will be adjusted up (or down) based on the user's preferred size.
 * If the user leaves the app, switches to Settings, and changes preferred size,
 * the text field will automatically update its size when the app returns to foreground.
 */
SSDynamicTextField *myTextField = [SSDynamicTextField textFieldWithFont:@"Courier" 
                                                               baseSize:16.0f];
myTextField.text = @"Auto-sizing text!";

SSDynamicTextView

A text view that responds when the user changes her preferred text size. Check out Example for a full example.

/**
 * Create a dynamic auto-sizing text view using a custom font and a base font size.
 * The font size will be adjusted up (or down) based on the user's preferred size.
 * If the user leaves the app, switches to Settings, and changes preferred size,
 * the text view will automatically update its size when the app returns to foreground.
 */
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];

Thanks!

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

About

UILabel/TextField/TextView/Button subclasses that support custom fonts with iOS 7's dynamic text sizes.

Resources

License

Stars

108 stars

Watchers

11 watching

Forks

Packages

 
 
 

Contributors