Xcode 6中的自定义字体

时间:2014-09-19 21:02:00

标签: ios xcode swift uifont

我有一个自定义字体,我已导入xcode,我想用作UIFont。当我尝试使用字体名称创建UIFont时,它不起作用。我试过通过每个字体系列中的所有字体来查看,但我看不到字体。但是当我去我的故事板时,我能够使用该字体。有人能指出我正确的方向吗?

这是打印字体的代码。该字体被称为Nexa Light和Nexa Bold(Apple表示真实姓名没有空格):

for family in UIFont.familyNames() as [String] {
    println("    ---" + family + "---")
    for font in UIFont.fontNamesForFamilyName(family) {
        println("        " + (font as String))
    }
}

下面是所有字体的输出:

---Marion---
    Marion-Italic
    Marion-Bold
    Marion-Regular
---Copperplate---
    Copperplate-Light
    Copperplate
    Copperplate-Bold
---Heiti SC---
    STHeitiSC-Medium
    STHeitiSC-Light
---Iowan Old Style---
    IowanOldStyle-Italic
    IowanOldStyle-Roman
    IowanOldStyle-BoldItalic
    IowanOldStyle-Bold
---Courier New---
    CourierNewPS-BoldMT
    CourierNewPS-ItalicMT
    CourierNewPSMT
    CourierNewPS-BoldItalicMT
---Apple SD Gothic Neo---
    AppleSDGothicNeo-Bold
    AppleSDGothicNeo-Thin
    AppleSDGothicNeo-UltraLight
    AppleSDGothicNeo-Regular
    AppleSDGothicNeo-Light
    AppleSDGothicNeo-Medium
    AppleSDGothicNeo-SemiBold
---Heiti TC---
    STHeitiTC-Medium
    STHeitiTC-Light
---Gill Sans---
    GillSans-Italic
    GillSans-Bold
    GillSans-BoldItalic
    GillSans-LightItalic
    GillSans
    GillSans-Light
---Marker Felt---
    MarkerFelt-Thin
    MarkerFelt-Wide
---Thonburi---
    Thonburi
    Thonburi-Bold
    Thonburi-Light
---Avenir Next Condensed---
    AvenirNextCondensed-BoldItalic
    AvenirNextCondensed-Heavy
    AvenirNextCondensed-Medium
    AvenirNextCondensed-Regular
    AvenirNextCondensed-HeavyItalic
    AvenirNextCondensed-MediumItalic
    AvenirNextCondensed-Italic
    AvenirNextCondensed-UltraLightItalic
    AvenirNextCondensed-UltraLight
    AvenirNextCondensed-DemiBold
    AvenirNextCondensed-Bold
    AvenirNextCondensed-DemiBoldItalic
---Tamil Sangam MN---
    TamilSangamMN
    TamilSangamMN-Bold
---Helvetica Neue---
    HelveticaNeue-Italic
    HelveticaNeue-Bold
    HelveticaNeue-UltraLight
    HelveticaNeue-CondensedBlack
    HelveticaNeue-BoldItalic
    HelveticaNeue-CondensedBold
    HelveticaNeue-Medium
    HelveticaNeue-Light
    HelveticaNeue-Thin
    HelveticaNeue-ThinItalic
    HelveticaNeue-LightItalic
    HelveticaNeue-UltraLightItalic
    HelveticaNeue-MediumItalic
    HelveticaNeue
---Gurmukhi MN---
    GurmukhiMN-Bold
    GurmukhiMN
---Times New Roman---
    TimesNewRomanPSMT
    TimesNewRomanPS-BoldItalicMT
    TimesNewRomanPS-ItalicMT
    TimesNewRomanPS-BoldMT
---Georgia---
    Georgia-BoldItalic
    Georgia
    Georgia-Italic
    Georgia-Bold
---Apple Color Emoji---
    AppleColorEmoji
---Arial Rounded MT Bold---
    ArialRoundedMTBold
---Kailasa---
    Kailasa-Bold
    Kailasa
---Kohinoor Devanagari---
    KohinoorDevanagari-Light
    KohinoorDevanagari-Medium
    KohinoorDevanagari-Book
---Sinhala Sangam MN---
    SinhalaSangamMN-Bold
    SinhalaSangamMN
---Chalkboard SE---
    ChalkboardSE-Bold
    ChalkboardSE-Light
    ChalkboardSE-Regular
---Superclarendon---
    Superclarendon-Italic
    Superclarendon-Black
    Superclarendon-LightItalic
    Superclarendon-BlackItalic
    Superclarendon-BoldItalic
    Superclarendon-Light
    Superclarendon-Regular
    Superclarendon-Bold
---Gujarati Sangam MN---
    GujaratiSangamMN-Bold
    GujaratiSangamMN
---Damascus---
    DamascusLight
    DamascusBold
    DamascusSemiBold
    DamascusMedium
    Damascus
---Noteworthy---
    Noteworthy-Light
    Noteworthy-Bold
---Geeza Pro---
    GeezaPro
    GeezaPro-Bold
---Avenir---
    Avenir-Medium
    Avenir-HeavyOblique
    Avenir-Book
    Avenir-Light
    Avenir-Roman
    Avenir-BookOblique
    Avenir-Black
    Avenir-MediumOblique
    Avenir-BlackOblique
    Avenir-Heavy
    Avenir-LightOblique
    Avenir-Oblique
---Academy Engraved LET---
    AcademyEngravedLetPlain
---Mishafi---
    DiwanMishafi
---Futura---
    Futura-CondensedMedium
    Futura-CondensedExtraBold
    Futura-Medium
    Futura-MediumItalic
---Farah---
    Farah
---Kannada Sangam MN---
    KannadaSangamMN
    KannadaSangamMN-Bold
---Arial Hebrew---
    ArialHebrew-Bold
    ArialHebrew-Light
    ArialHebrew
---Arial---
    ArialMT
    Arial-BoldItalicMT
    Arial-BoldMT
    Arial-ItalicMT
---Party LET---
    PartyLetPlain
---Chalkduster---
    Chalkduster
---Hiragino Kaku Gothic ProN---
    HiraKakuProN-W6
    HiraKakuProN-W3
---Hoefler Text---
    HoeflerText-Italic
    HoeflerText-Regular
    HoeflerText-Black
    HoeflerText-BlackItalic
---Optima---
    Optima-Regular
    Optima-ExtraBlack
    Optima-BoldItalic
    Optima-Italic
    Optima-Bold
---Palatino---
    Palatino-Bold
    Palatino-Roman
    Palatino-BoldItalic
    Palatino-Italic
---Malayalam Sangam MN---
    MalayalamSangamMN-Bold
    MalayalamSangamMN
---Lao Sangam MN---
    LaoSangamMN
---Al Nile---
    AlNile-Bold
    AlNile
---Bradley Hand---
    BradleyHandITCTT-Bold
---Hiragino Mincho ProN---
    HiraMinProN-W6
    HiraMinProN-W3
---Trebuchet MS---
    Trebuchet-BoldItalic
    TrebuchetMS
    TrebuchetMS-Bold
    TrebuchetMS-Italic
---Helvetica---
    Helvetica-Bold
    Helvetica
    Helvetica-LightOblique
    Helvetica-Oblique
    Helvetica-BoldOblique
    Helvetica-Light
---Courier---
    Courier-BoldOblique
    Courier
    Courier-Bold
    Courier-Oblique
---Cochin---
    Cochin-Bold
    Cochin
    Cochin-Italic
    Cochin-BoldItalic
---Devanagari Sangam MN---
    DevanagariSangamMN
    DevanagariSangamMN-Bold
---Oriya Sangam MN---
    OriyaSangamMN
    OriyaSangamMN-Bold
---Snell Roundhand---
    SnellRoundhand-Bold
    SnellRoundhand
    SnellRoundhand-Black
---Zapf Dingbats---
    ZapfDingbatsITC
---Bodoni 72---
    BodoniSvtyTwoITCTT-Bold
    BodoniSvtyTwoITCTT-Book
    BodoniSvtyTwoITCTT-BookIta
---Verdana---
    Verdana-Italic
    Verdana-BoldItalic
    Verdana
    Verdana-Bold
---American Typewriter---
    AmericanTypewriter-CondensedLight
    AmericanTypewriter
    AmericanTypewriter-CondensedBold
    AmericanTypewriter-Light
    AmericanTypewriter-Bold
    AmericanTypewriter-Condensed
---Avenir Next---
    AvenirNext-UltraLight
    AvenirNext-UltraLightItalic
    AvenirNext-Bold
    AvenirNext-BoldItalic
    AvenirNext-DemiBold
    AvenirNext-DemiBoldItalic
    AvenirNext-Medium
    AvenirNext-HeavyItalic
    AvenirNext-Heavy
    AvenirNext-Italic
    AvenirNext-Regular
    AvenirNext-MediumItalic
---Baskerville---
    Baskerville-Italic
    Baskerville-SemiBold
    Baskerville-BoldItalic
    Baskerville-SemiBoldItalic
    Baskerville-Bold
    Baskerville
---Khmer Sangam MN---
    KhmerSangamMN
---Didot---
    Didot-Italic
    Didot-Bold
    Didot
---Savoye LET---
    SavoyeLetPlain
---Bodoni Ornaments---
    BodoniOrnamentsITCTT
---Symbol---
    Symbol
---Menlo---
    Menlo-Italic
    Menlo-Bold
    Menlo-Regular
    Menlo-BoldItalic
---Bodoni 72 Smallcaps---
    BodoniSvtyTwoSCITCTT-Book
---DIN Alternate---
    DINAlternate-Bold
---Papyrus---
    Papyrus
    Papyrus-Condensed
---Euphemia UCAS---
    EuphemiaUCAS-Italic
    EuphemiaUCAS
    EuphemiaUCAS-Bold
---Telugu Sangam MN---
    TeluguSangamMN
    TeluguSangamMN-Bold
---Bangla Sangam MN---
    BanglaSangamMN-Bold
    BanglaSangamMN
---Zapfino---
    Zapfino
---Bodoni 72 Oldstyle---
    BodoniSvtyTwoOSITCTT-Book
    BodoniSvtyTwoOSITCTT-Bold
    BodoniSvtyTwoOSITCTT-BookIt
---DIN Condensed---
    DINCondensed-Bold

这两种字体都会添加到plist中并添加到构建阶段。

5 个答案:

答案 0 :(得分:1)

您是否已将字体添加到Info.plist中。例如:

Fonts in plist file

答案 1 :(得分:0)

所以我从项目中删除了字体并重新加载它们并且它有效!

我不确定究竟是什么让它发挥作用,但我通过了article中的所有步骤。

答案 2 :(得分:0)

您需要提取字体,并将它们添加到info.plist中。换句话说,将它们下载到您的项目中,然后您就可以通过编程方式访问它们,我也相信通过可视侧边栏方式。

答案 3 :(得分:0)

将字体添加到Info.plist中。将其放入由应用程序提供的字体

enter image description here

在Target Project中添加自定义字体==>构建阶段==>复制捆绑资源 enter image description here

在代码中使用自定义字体:

UILable *lblCostum = [[UILable alloc] initWithFrame:CGRectMake(295,60, 21, 20)];
lblCostum.font = [UIFont fontWithName:@"BirdsofParadise" size:12];

答案 4 :(得分:0)

感谢您的代码并帮助了我。使用Xcode 8的代码可以是:

for family in UIFont.familyNames {
    print("    ---\(family)---")
    for font in UIFont.fontNames(forFamilyName: family) {
        print("       \(font)")
    }
}