简体   繁体   中英

Change Default Font in Xcode 8 Swift 3 IOS

Is there any way to change the default font of the Application from one place, not each view controller and not each element category??

for example in html and CSS, you can define the global font from CSS with one line of code. Thanks.

I don't know if its what you ask, but you can change all the fonts in your app in appDelegate. Will change all the fonts in the buttons, labels, etc.

you can do it creating a extension form UILabel like this

extension UILabel {

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

then in the didFinishLaunchingWithOptions in your appDelegate you can call the variable and pass the name of the font you want, like this:

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

当您将字体添加到info.plist时,您已经更改了Xcode的默认字体,尝试将UILabel字体保留为系统字体,仅更改样式并运行应用程序,您将拥有所需的内容。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM