WatchKit WKInterfaceLabel cannot change font

I am trying to change the font of the label. But each font installed in the attribute inspector is different from the system font - it does not change anything - neither the simulator nor the storyboard. I even tried installing the font programmatically using the Attributed line - the same system font will appear. Thank you for your help.

+7
ios fonts watchkit
source share
1 answer

You cannot currently use the included iOS fonts in WatchKit. Only system available (San Francisco). Source: Apple Developer Forums

However, you can use your own font by adding a font file to the project:

  • Drag and drop font files into the project navigator

    font in the project navigator

  • Include a custom font file in your WatchKit app and WatchKit extension.

    add both goals

  • Add the fonts provided by the application (UIAppFonts) to both your WatchKit and WatchKit Extension Info.plist application

    font in plist

  • Add this code to awakeWithContext to find out the correct font name, so you can call your code later:

     print("Custom font names:") print(UIFont.fontNames(forFamilyName: "Exo")) print(UIFont.fontNames(forFamilyName: "Tabardo")) 
  • Launch the application and pay attention to the font names printed on the debug console. When you know the correct name, you can add this code somewhere in the WatchKit extension:

     var fontSize = CGFloat(32) var text = "so cool" var cstmFont = UIFont(name: "Tabardo", size: fontSize)! var attrStr = NSAttributedString(string: text, attributes: [NSFontAttributeName: cstmFont]) firstLabel.setAttributedText(attrStr) fontSize = CGFloat(36) text = "right on!" cstmFont = UIFont(name: "Exo-Regular", size: fontSize)! attrStr = NSAttributedString(string: text, attributes: [NSFontAttributeName: cstmFont]) secondLabel.setAttributedText(attrStr) 
  • Customize custom fonts on your watch!

    watch user font interface

Keep in mind that looks and notifications cannot use custom fonts. If you want to use it there, you will have to use a rendered image. However, since views and notifications must load quickly, you will want this image to be ready for use when it is called up.

+13
source share

All Articles