[英]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解决方法取决于什么对您更重要
UIImageView
subview hierarchy in the xib is most important 1.在xib中创建UIImageView
子视图层级最重要Start with a UIView
but change it's class to UIImageView
从UIView
开始,但将其从 class 更改为UIImageView
then set the image in code然后在代码中设置图片
self.myImageView.image = [UIImage imageNamed:@"someImage"];
Then do as you have been doing and add the subviews in code然后按照你一直在做的,在代码中添加子视图
[self.myImageView addSubview:someSubView];
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.