在Interface Builder中,UIButton的动态类型“自动调整字体”设置等效?

UILabel在Interface Builder的“属性”检查器中具有“ Dynamic Type: Automatically Adjusts Font复选框。

Interface Builder中是否有等效的自动调整UIButton的字体大小,还是必须在代码中处理?

我正在使用Xcode 9.0 beta 6,目标是iOS 11。

显然没有,但解决起来并不是很难。 您可以使用@IBInspectable属性在UIButton上进行扩展:

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

现在,您只需为每个UIButton(或其任何子类)启用它。

Interface Builder