Search code examples
swiftxcodeswift3colorswatchkit

Is there an easy way to identify the colour of text in Watch Kit - Swift


I am creating a program which makes a label a random UIcolor like 'red' or 'green'. I want to identify that colour. I know how to do it on an iPhone but how do I do it in whatchKit. This is what I have for the iPhone:

if ageLabel.textColor == UIColor.green {
    print("Its green")
}

Solution

  • Short answer: no. If you look at the class reference of WKInterfaceLabel, you can see, that it only has methods to set the text and the properties of the text, but it has no getter methods. However, if you are setting textColor programatically, you can store the set colour in a separate variable every time you call the setTextColor(_:) function.