Skip to content

Instantly share code, notes, and snippets.

@emiellensink
Created July 7, 2017 14:54
Show Gist options
  • Save emiellensink/5c379f6ae7a0bfbbd6f6e7146b13b63a to your computer and use it in GitHub Desktop.
Save emiellensink/5c379f6ae7a0bfbbd6f6e7146b13b63a to your computer and use it in GitHub Desktop.
UIControl+dynamicType.swift
//
// UIControl+dynamicType.swift
//
// Created by Emiel Lensink | The Mobile Company on 28/06/2017.
// Copyright © 2017 The Mobile Company. All rights reserved.
//
import UIKit
extension UILabel {
@IBInspectable var isDynamicBody: Bool {
get { return false }
set {
if #available(iOS 11.0, *) {
if let font = font {
self.font = UIFontMetrics(forTextStyle: .body).scaledFont(for: font)
adjustsFontForContentSizeCategory = true
adjustsFontSizeToFitWidth = true
}
}
}
}
@IBInspectable var isDynamicHeader: Bool {
get { return false }
set {
if #available(iOS 11.0, *) {
if let font = font {
self.font = UIFontMetrics(forTextStyle: .headline).scaledFont(for: font)
adjustsFontForContentSizeCategory = true
adjustsFontSizeToFitWidth = true
}
}
}
}
}
extension UIButton {
@IBInspectable var isDynamicBody: Bool {
get { return false }
set {
if #available(iOS 11.0, *) {
if let label = self.titleLabel, let font = label.font {
label.font = UIFontMetrics(forTextStyle: .body).scaledFont(for: font)
label.adjustsFontForContentSizeCategory = true
label.adjustsFontSizeToFitWidth = true
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment