Create ImageView programmatically in Watch Kit

I am trying to create an image view for a watch application, I am trying to create programmatically, but the code used in the classic view controller does not work.

let imageName = "yourImage.png" let image = UIImage(named: imageName) let imageView = UIImageView(image: image!) imageView.frame = CGRect(x: 0, y: 0, width: 50, height: 50) view.addSubview(imageView) 

How can I do the same for dialing a watch? thanks

+6
source share
1 answer

You cannot dynamically create views in WatchKit. You need to create the whole interface in the storyboard. You can hide the elements of your storyboard, and then programmatically display them.

In your storyboard, you can use WKInterfaceImage to store the image. You can set the image at runtime using setImage:

+12
source

Source: https://habr.com/ru/post/980169/


All Articles