Apple Interface Builder:将子视图添加到UIImageView [英] Apple Interface Builder: adding subview to UIImageView

查看:102
本文介绍了Apple Interface Builder:将子视图添加到UIImageView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Interface Bulder的帮助下创建了 UIImageView 。现在我想在其中放置标签(作为其子视图)。在代码中我可以键入类似的内容: [myUIImageView addSubview:myUILabel]; 但是我可以在IB的帮助下完成吗?我找到了 UIView 的解决方案,但找不到与 UIImageView 类似的东西。

I created UIImageView with the help of Interface Bulder. Now I want to place label inside it (as its subview). In code I can type something like: [myUIImageView addSubview:myUILabel]; But can I do it with the help of IB? I found the solution for UIView, but can't find something similar for UIImageView.

推荐答案

您无法在界面构建器中向UIImageView添加子视图,原因仅为Apple所知!你说你可以通过编程方式添加子视图是正确的,但是,设置自动调整掩码和子视图的放置的开销都应该在代码中处理,这很麻烦。

You cannot add a subview to UIImageView in interface builder for reasons only known to Apple! You are right in saying that you can addSubview programmatically, but then, the overhead of setting autoresizing masks and placements of subviews should all be handled in code, which is cumbersome.

所以有一个简单的解决方法。不要在nib中拖动UIImageView的实例,只需拖动UIView并从UIView(检查器的cmd + 4选项)将其类更改为UIImageView。您在nib中为默认的imageView实例和新的UIImageView子类实例找到的唯一区别是:您无法从nib(cmd + 1选项)将图像设置为新的imageView。因此,在其相应viewController的 -viewDidLoad 方法中,将image设置为UIImageView的这个插座。

So there is an easy workaround. Instead of dragging an instance of UIImageView in the nib, just drag a UIView and change its class to UIImageView from UIView (cmd+4 option of inspector). The only difference you find in the nib for default imageView instance and your new UIImageView subclass instance is: you cannot set image to your new imageView from nib (cmd+1 option). So, in the -viewDidLoad method of its appropriate viewController, set image to this outlet of UIImageView.

通过执行因此,您可以自由地在界面构建器中将子视图添加到now UIImageView实例中,这非常简单。

By doing so, you are free to add subviews to your "now UIImageView" instances in interface builder, which is much easy.

希望这会有所帮助。 。 。

Hope this helps . . .

这篇关于Apple Interface Builder:将子视图添加到UIImageView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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