在Xcode日志中找不到字体SKLabelNode警告

时间:2017-04-25 09:58:10

标签: ios swift xcode sprite-kit watchkit

我正在使用精灵工具包在我的苹果手表中创建自定义视图。我已经为SKLabelNode添加了自定义字体。当我在设备中运行代码并观看时,该字体已应用并且也可以使用。但每次我都低于警告

  

SKLabelNode:找不到“SFCompactText-Regular”字体。

字体应用于标签并且工作完美且不会崩溃。那为什么每次都会显示这个警告?

以下是来自Apple watch输出的列表:

Arial Hebrew
   ArialHebrew-Bold
   ArialHebrew-Light
   ArialHebrew
Myanmar Sangam MN
   MyanmarSangamMN-Bold
   MyanmarSangamMN
Oriya Sangam MN
   OriyaSangamMN-Bold
   OriyaSangamMN
Symbol
   Symbol
Gurmukhi MN
   GurmukhiMN-Bold
   GurmukhiMN
Tamil Sangam MN
   TamilSangamMN-Bold
   TamilSangamMN
Courier New
   CourierNewPSMT
   CourierNewPS-BoldMT
   CourierNewPS-BoldItalicMT
   CourierNewPS-ItalicMT
Courier
   Courier-BoldOblique
   Courier-Oblique
   Courier
   Courier-Bold
Kohinoor Bangla
   KohinoorBangla-Regular
   KohinoorBangla-Semibold
   KohinoorBangla-Light
Apple Color Emoji
   AppleColorEmoji
Lao Sangam MN
   LaoSangamMN
Bangla Sangam MN
Telugu Sangam MN
Kailasa
   Kailasa-Bold
   Kailasa
PingFang TC
   PingFangTC-Light
   PingFangTC-Thin
   PingFangTC-Ultralight
   PingFangTC-Semibold
   PingFangTC-Regular
   PingFangTC-Medium
Heiti SC
Malayalam Sangam MN
   MalayalamSangamMN
   MalayalamSangamMN-Bold
Thonburi
   Thonburi
   Thonburi-Bold
   Thonburi-Light
Zapf Dingbats
   ZapfDingbatsITC
Kohinoor Telugu
   KohinoorTelugu-Medium
   KohinoorTelugu-Regular
   KohinoorTelugu-Light
Avenir Next
   AvenirNext-HeavyItalic
   AvenirNext-DemiBoldItalic
   AvenirNext-BoldItalic
   AvenirNext-UltraLight
   AvenirNext-MediumItalic
   AvenirNext-Bold
   AvenirNext-Medium
   AvenirNext-Italic
   AvenirNext-UltraLightItalic
   AvenirNext-Regular
   AvenirNext-Heavy
   AvenirNext-DemiBold
Apple SD Gothic Neo
   AppleSDGothicNeo-Bold
   AppleSDGothicNeo-Medium
   AppleSDGothicNeo-UltraLight
   AppleSDGothicNeo-Regular
   AppleSDGothicNeo-Light
   AppleSDGothicNeo-Thin
   AppleSDGothicNeo-SemiBold
Helvetica
   Helvetica-BoldOblique
   Helvetica-Light
   Helvetica-Oblique
   Helvetica-LightOblique
   Helvetica-Bold
   Helvetica
Euphemia UCAS
   EuphemiaUCAS
   EuphemiaUCAS-Italic
   EuphemiaUCAS-Bold
PingFang SC
   PingFangSC-Thin
   PingFangSC-Medium
   PingFangSC-Regular
   PingFangSC-Ultralight
   PingFangSC-Semibold
   PingFangSC-Light
PingFang HK
   PingFangHK-Thin
   PingFangHK-Ultralight
   PingFangHK-Semibold
   PingFangHK-Light
   PingFangHK-Medium
   PingFangHK-Regular
Gujarati Sangam MN
   GujaratiSangamMN
   GujaratiSangamMN-Bold
Heiti TC
Sinhala Sangam MN
   SinhalaSangamMN-Bold
   SinhalaSangamMN
Kannada Sangam MN
   KannadaSangamMN
   KannadaSangamMN-Bold
Hiragino Sans
   HiraginoSans-W3
   HiraginoSans-W6
Khmer Sangam MN
   KhmerSangamMN
Times New Roman
   TimesNewRomanPSMT
   TimesNewRomanPS-ItalicMT
   TimesNewRomanPS-BoldItalicMT
   TimesNewRomanPS-BoldMT
Geeza Pro
   GeezaPro
   GeezaPro-Bold
Helvetica Neue
   HelveticaNeue-ThinItalic
   HelveticaNeue-CondensedBold
   HelveticaNeue-Light
   HelveticaNeue-UltraLightItalic
   HelveticaNeue-CondensedBlack
   HelveticaNeue-MediumItalic
   HelveticaNeue-Thin
   HelveticaNeue-Italic
   HelveticaNeue-Bold
   HelveticaNeue
   HelveticaNeue-LightItalic
   HelveticaNeue-UltraLight
   HelveticaNeue-BoldItalic
   HelveticaNeue-Medium
Kohinoor Devanagari
   KohinoorDevanagari-Regular
   KohinoorDevanagari-Semibold
   KohinoorDevanagari-Light
Avenir
   Avenir-Roman
   Avenir-Black
   Avenir-BlackOblique
   Avenir-HeavyOblique
   Avenir-Oblique
   Avenir-Medium
   Avenir-Light
   Avenir-MediumOblique
   Avenir-BookOblique
   Avenir-LightOblique
   Avenir-Book
   Avenir-Heavy

2 个答案:

答案 0 :(得分:5)

我通过以下步骤解决了我的问题:

- 在Watch Extension target中添加了我的字体。

- 为WatchApp和WatchExtension增加了目标成员资格。

- 在WatchApp和WatchExtension info.plist文件中添加了字体输入。

- 使用以下代码检查实际的字体名称。

for fontFamily in UIFont.familyNames {
        print("Font family name = \(fontFamily as String)")
        for fontName in UIFont.fontNames(forFamilyName: fontFamily as String) {
            print("- Font name = \(fontName)")
        }
}

为我的自定义字体处理了一个结构常量。

struct UIFontConst {
    static let SF_COMPACT_TEXT_REGULAR  = UIFont(name: "SFCompactText-Regular", size: 9.0)
}

- 使用类似UIFontConst.SF_COMPACT_TEXT_REGULAR?.fontName

答案 1 :(得分:0)

如果您想摆脱错误,可以直接从Apple https://developer.apple.com/fonts/下载字体。

旧金山是macOS,iOS,watchOS和tvOS的新系统字体。如果您有兴趣,可以在字体上使用WWDC视频,这是一款非常棒的手表:https://developer.apple.com/videos/play/wwdc2016/803/