添加自定义字体不适用于iOS

时间:2018-03-27 08:44:38

标签: ios swift

您好我需要在我的操场上添加一些Font,第一个工作,第二个工作,我下载了一个字体,安装了它,添加到资源文件夹中,并在Xcode中添加了这段代码,但它不工作,有人可以帮助我吗?

let fontURL = Bundle.main.url(forResource: "VAGRoundedBold", withExtension: "ttf")
        CTFontManagerRegisterFontsForURL(fontURL! as CFURL, CTFontManagerScope.process, nil)    
let fontURL3 = Bundle.main.url(forResource: "conduit_itc", withExtension: "ttf")
        CTFontManagerRegisterFontsForURL3(fontURL! as CFURL, CTFontManagerScope.process, nil) 

    buttonYellow.setTitle("Optimism", for: .normal)
    buttonYellow.titleLabel?.font = UIFont(name: "VAGRoundedBold", size: 40)
    buttonRed.setTitle("Strenght", for: .normal)
    buttonRed.titleLabel?.font = UIFont(name:"conduit_itc", size: 40)

EDIT。我不知道问题是什么,但从dafont工作下载,从其他网站下载不起作用

1 个答案:

答案 0 :(得分:0)

  • 首先:将下载的字体添加到您的项目中
  • 第二:打开Info.plist并添加

    <key>UIAppFonts</key> <array> <string> VAGRoundedBold.ttf</string> </array>

  • 上次:使用

  • 中的字体

let yourFont = UIFont(name: "VAGRoundedBold", size: <your_size>)!

相关问题