Created
July 7, 2017 14:54
-
-
Save emiellensink/5c379f6ae7a0bfbbd6f6e7146b13b63a to your computer and use it in GitHub Desktop.
UIControl+dynamicType.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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