1

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!

Phil
  • 3,934
  • 12
  • 38
  • 62
Zhang Zhan
  • 815
  • 8
  • 27
  • Does this answer your question? [Create imageView programmatically in Watch Kit](https://stackoverflow.com/questions/27658498/create-imageview-programmatically-in-watch-kit) – Tamás Sengel Dec 13 '22 at 21:05

1 Answers1

6

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.

Benjamin Mayo
  • 6,649
  • 2
  • 26
  • 25
  • Thank you for your reply. If that's the case, is it possible to update the label's location programmatically? I noticed in the storyboard I can only specify top, center and bottom. I want to move the label to a certain location such as 20, 30 – Zhang Zhan Feb 24 '15 at 13:17
  • Apple Watch's layout system is different from iOS.So there is no frame,no bounds,and even no auto layout.Instead of positioning UIElements with (x,y),you should place them horizontally or vertically.And you could also use group to wrap them or nest group to make complicated layout. – tounaobun Mar 23 '15 at 14:32
  • tutorials for watchkit : http://www.appcoda.com/watchkit/ Hope it might help you to understand better – aashish tamsya Nov 20 '15 at 07:36