Search code examples
swiftuilabelwatchkitwkinterfacelabel

Set different font styles for WKInterfaceLabel with multiple lines


I'm developing an apple watch app - it consists of two tables that contain labels.

These labels have two lines of text, I want the second line of text to have a different font style to the top line

How can I do this in swift?

Thanks everyone


Solution

  • The easiest way to do this would be to create two labels in your storyboard, each with their own font style. Then, use setText to set the first and second lines.

    Unfortunately, WKInterfaceLabel doesn't provide any typesetting metrics, so there's no built-in method to determine where a line-break occurs. If you need to determine where a line-break occurs, you'll likely have to perform your own typesetting in the Watch extension, then choose to set two different labels or a single label with an NSAttributedString.