【问题标题】:My fontSize doesn't work with my custom font我的 fontSize 不适用于我的自定义字体
【发布时间】:2016-01-02 00:14:14
【问题描述】:

我在我的项目中导入我的字体

我创建了一个类 style.swift

struct Style {


    //fonts
    static var GothamBlackItalic = UIFont(name: "Gotham-BlackItalic.ttf", size: 12)
    static var GothamBold = UIFont(name: "Gotham-Bold.ttf", size: 12)
    static var GothamBoldItalic = UIFont(name: "Gotham-BoldItalic.ttf", size: 12)
    static var GothamBook = UIFont(name: "Gotham-Book.ttf", size: 12)
    static var GothamBookItalic = UIFont(name: "Gotham-BookItalic.ttf", size: 12)
    static var GothamLight = UIFont(name: "Gotham-Light.ttf", size: 12)
    static var GothamLightItalic = UIFont(name: "Gotham-LightItalic.ttf", size: 12)
    static var GothamMedium = UIFont(name: "Gotham-Medium.ttf", size: 4)
    static var GothamMediumItalic = UIFont(name: "Gotham-MediumItalic.ttf", size: 12)
    static var GothamThin = UIFont(name: "Gotham-Thin.ttf", size: 12)
    static var GothamThinItalic = UIFont(name: "Gotham-ThinItalic.ttf", size: 12)
    static var GothamUltra = UIFont(name: "Gotham-Ultra.ttf", size: 12)
    static var GothamUltraItalic = UIFont(name: "Gotham-UltraItalic.ttf", size: 12)
    static var GothamExtraLight = UIFont(name: "Gotham-XLight.ttf", size: 12)
    static var GothamExtraLightItalic = UIFont(name: "Gotham-XLightItalic.ttf", size: 12)

}

在我的视图控制器中,我在标签中调用字体 GothamMedium :

myLabel.font=Style.GothamMedium

字体正确但字体大小无效。 您能告诉我如何更改字体大小吗?

【问题讨论】:

  • 不工作怎么办?标签上有什么设置?你有没有调试过在运行时检查标签设置?

标签: ios swift fonts font-size uifont


【解决方案1】:

font namefont file name 之间存在差异,您提到的是font file name,而不是font name。双击字体,它会在Font Book打开,标题是font name现在font应该被创建为

static var GothamBlackItalic = UIFont(name: "Gotham Black", size: 12)

在您的plist 中添加Fonts provided by application。看到这个link

【讨论】:

    猜你喜欢
    • 2012-10-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-29
    • 2019-04-24
    • 1970-01-01
    • 2012-08-23
    相关资源
    最近更新 更多