Reputation: 561
Has anyone found a way to retrieve attributes of a WKInterfaceObject, for example the content frame or font attributes? There seem to be functions for setting these attributes but not accessing the existing ones.
I'm trying to use WKInterfaceLabel.setAttributedText()
to set text such as "XXXyy" where the "yy" portion is set to a font that is smaller by a percentage of the original font size. But I can't find any way to access the original font size. Nor can I find a way to approximate by accessing the dimensions of the object. For now I'm working around by hard-coding the font size, but that is becoming increasingly difficult because I need to specify device-specific font attributes in the storyboard.
Upvotes: 1
Views: 421
Reputation:
As you've seen from the documentation, a WKInterfaceObject
has no getter methods.
Communication between an interface object in your extension and the corresponding view on Apple Watch is one way, with information flowing from your WatchKit extension to Apple Watch. In other words, you set values on an interface object, but you cannot get the current values of its attributes. There are performance and latency implications for retrieving data from Apple Watch, making changes, and writing those changes back to the device. So it is recommended that you maintain information about the configuration of your interface in your WatchKit extension.
There's no way that you'll be able to obtain device-specific attributes set by Storyboard from the WatchKit
object itself.
One possible workaround would be to use two adjacent labels for the XXX and yy strings. Then you could specify a relatively smaller (system or text style) font in Storyboard, along with the original font.
Upvotes: 1