在 Watch Kit 中以编程方式创建 imageView [英] Create imageView programmatically in Watch Kit

查看:26
本文介绍了在 Watch Kit 中以编程方式创建 imageView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为手表应用创建图像视图,我正在尝试以编程方式创建,但经典视图控制器中使用的代码不起作用.

i'm trying to create an image view for a watch app, i'm trying to create programmatically but the code used in a classic view controller doesn't 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 i can do the same thing for watch kit? thanks

推荐答案

您不能在 WatchKit 中动态创建视图.您需要在情节提要中创建整个界面.您可以隐藏故事板的元素,然后以编程方式取消隐藏它们.

You can't dynamically create views in WatchKit. You need to create your entire interface in a storyboard. You can have elements of your storyboard hidden and then programmatically unhide them.

在情节提要中,您可以使用 WKInterfaceImage 来保存图像.您可以在运行时使用 setImage: 设置图像.

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

这篇关于在 Watch Kit 中以编程方式创建 imageView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆