Search code examples
objective-capple-watch

How to add a label to AppleWatch programmatically?


I'm new to AppleWatch development but I find I can't add a label (or button) to AppleWatch screen programmatically. All I can do is just adding the assets via storyboard.

Can I ask how to add label or button to the screen programmatically? And how to set their position to x and y on the screen? Objective C solution is preferred.

Thank you!


Solution

  • You can't. View hierarchy in Apple Watch development is statically declared in storyboards at compile time. If you want a label to be conditionally visible, make it in the storyboard and set it to hidden. It is then possible to unhide the view programmatically at runtime.