ios - 在 Xcode 8 Swift 3 IOS 中更改默认字体

标签 ios swift3 xcode8

有没有办法从一个地方更改应用程序的默认字体,而不是每个 View Controller 而不是每个元素类别?

例如在 html 和 CSS 中,您可以使用一行代码从 CSS 定义全局字体。 谢谢。

最佳答案

我不知道是不是你问的,但你可以在 appDelegate 中更改应用程序中的所有字体。将更改按钮、标签等中的所有字体。

你可以像这样创建一个扩展表单 UILabel

extension UILabel {

    var substituteFontName : String {
        get { return self.font.fontName }
        set { self.font = UIFont(name: newValue, size: self.font.pointSize) }
    }
}

然后在您的 appDelegate 的 didFinishLaunchingWithOptions 中,您可以调用变量并传递所需字体的名称,如下所示:

UILabel.appearance().substituteFontName = "Kyrial Sans Pro"

关于ios - 在 Xcode 8 Swift 3 IOS 中更改默认字体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42552393/

相关文章:

objective-c - 一次显示一定行数,点击按钮,显示更多

iOS 与 XMPP 的连接失败

xcode8 - Xcode 8 需要永远停留在断点上

ios - 升级后 Alamofire 不工作(Swift/Xcode 8)

ios - 如何在 Realm 中实现继承(iOS、Objective C)

iphone - S3PutObjectRequest 在取消之前的 putObjectRequest 后上传失败

objective-c - Decimal 在 Swift 3 中作为 NSDecimal 而不是 NSDecimalNumber 导入到 Objective C

ios - swift 3 : How to center horizontally the last row of cells in a UICollectionView with only one section?

image - Swift 3 图像下载无法完全正常工作

swift3 - 错误 : not conform to protocol 'Equatable'