Search code examples
swiftwatchkitapple-watch

Changing WKInterfaceLabel Text


I currently have:

@IBOutlet var label: WKInterfaceLabel!

and

 let myString = "Swift Attributed String"
 let myAttribute = [ NSAttributedStringKey.foregroundColor: UIColor.blue ]
 let myAttrString = NSAttributedString(string: myString, attributes: myAttribute)
 label.setAttributedText(myAttrString)

Currently this code does not change the text of the label. Is there something obvious I am missing? Thanks for any help!


Solution

  • Your code is working perfectly fine but for only textcolor You do not need to use attributed property you can directly use setTextColor() property.

    label.setTextColor(UIColor.blue)
    label.setText(myString)
    

    You can refer WKInterfaceLabel and setTextColor