Equivalent of dynamic type “automatically adjusts font” setting for UIButton in Interface Builder?

自古美人都是妖i 提交于 2020-01-01 04:16:04

问题


A UILabel has a Dynamic Type: Automatically Adjusts Font check-box in the Attributes Inspector in Interface Builder.

Is there an equivalent in Interface Builder for automatically adjusting the font size of a UIButton, or does this have to be handled in code?

I'm using Xcode 9.0 beta 6, targeting iOS 11.


回答1:


Apparently there isn't, but it's not very hard to fix. You can make an extension on UIButton with an @IBInspectable property:

extension UIButton {

    @IBInspectable
    var adjustsFontForContentSizeCategory: Bool {
        set {
            self.titleLabel?.adjustsFontForContentSizeCategory = newValue
        }
        get {
            return self.titleLabel?.adjustsFontForContentSizeCategory ?? false
        }
    }
}

Now you can simply turn it on for every UIButton (or any of its subclasses).



来源:https://stackoverflow.com/questions/46139099/equivalent-of-dynamic-type-automatically-adjusts-font-setting-for-uibutton-in

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!