Skip to content

Support dynamic font size #41

@tedgonzalez

Description

@tedgonzalez

source: https://developer.apple.com/videos/play/wwdc2017/245/

system font

label.font = UIFont.preferredFont(forTextStyle: style)
label.adjustsFontForContentSizeCategory = true

where style is based on:
Screen Shot 2019-12-15 at 10 23 11 AM

custom font

/// ios 11 
label.font = UIFontMetrics.default.scaledFont(for: customFont) //default means .body
label.font = UIFontMetrics(forTextStyle: style).scaledFont(for: customFont)

/// Make sure to set lines to 0

label.numberOfLines = 0

layout (Auto layout Techniques in Interface Builder WWDC 2017)

secondLabel.firstBaselineAnchor.constraintEqualToSystemSpacingBelow(firstLabel.lastBaselineAnchor, multiplier: 1.0)

/// For side to side labels

if traitCollection.preferredContentSizeCategory > .extraLarge {
    // vertical stack
} else {
    // horizontal stack
}

/// updating layout when traitCollection changes

override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
    if traitCollection.preferredContentSizeCategory.isAccessibilityCategory != previousTraitCollection?.preferredContentSizeCategory.isAccessibilityCategory {
        /// updateLayout
    }
}

/// Table Views
/// standard table views with detail text label adjust automatically

tableView.rowHeight = UITableViewAutomaticDimension
tableView.estimatedRowHeight = <a reasonable estimate>

tableView.sectionHeaderHeight = UITableViewAutomaticDimension
tableView.estimatedSectionHeaderHeight = <a reasonable estimate>

tableView.sectionFooterHeight = UITableVIewAutomaticDimension
tableView.estimatedSectionFooterHeight = <a reasonable estimate>

/// images in UIImageView, UIButton, NSTextAttachment
Use pdf, preserve vector data checkbox in asset catalog
Interface builder
Screen Shot 2019-12-15 at 10 55 22 AM

imageView.adjustsImageSizeForAccessibilityContentSizeCategory = true

/// images in tabBarItems
Use pdf, preserve vector data checkbox in asset catalog
/// images in tabBarItems that doesn't have pdf
barButtonItem.largeContentSizeImage = largerImage

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions