简体   繁体   English

通过界面生成器将子视图添加到 UIImageView

[英]add subview to UIImageView via interface builder

Is such thing possible?这样的事情可能吗? I have my UIScrollView created via IB and I wanted it as a subview of a UIImgeView I have, created in IB as well.我有我的 UIScrollView 通过 IB 创建,我希望它作为我拥有的 UIImgeView 的子视图,也是在 IB 中创建的。 If it is possible how do I do so?如果可能的话,我该怎么做?

Short answer NO .简短回答NO The workarounds depend on what's more important to you解决方法取决于什么对您更重要

1. Creating the UIImageView subview hierarchy in the xib is most important 1.在xib中创建UIImageView子视图层级最重要

Start with a UIView but change it's class to UIImageViewUIView开始,但将其从 class 更改为UIImageView

在此处输入图像描述

then set the image in code然后在代码中设置图片

self.myImageView.image = [UIImage imageNamed:@"someImage"];

2. Setting the image in the xib is most important 2.在xib中设置image最重要

Then do as you have been doing and add the subviews in code然后按照你一直在做的,在代码中添加子视图

[self.myImageView addSubview:someSubView];

3. You want the imageView and the other view to move and scale in unison 3. 您希望 imageView 和另一个视图一致移动和缩放

Then place them in a container UIView that is the same size as the UIImageView然后将它们放在与UIImageView大小相同的容器UIView

在此处输入图像描述

Here you can see a container UIView that holds the UIImageView and another subview在这里你可以看到一个container UIView包含UIImageView和另一个子视图

If you can't drag it into the UIImageView then I do not think it is possible,and an imageViews purpose is not meant to hold subviews.如果你不能将它拖到 UIImageView 那么我认为这是不可能的,并且 imageViews 的目的并不意味着持有子视图。 But it is just as easy to add it in code但是在代码中添加它同样容易

[imageView addSubview:subView];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM