如何在Superview的视图中插入视图? (iOS) [英] How to Insert View in Superview's View? (iOS)

查看:162
本文介绍了如何在Superview的视图中插入视图? (iOS)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在下面的代码行...如何修改它以在名为'foo'的超级视图视图中插入子视图?

I have the line of code below... How would I modify it to insert the subview in the superview's view named 'foo'?

[[self superview] addSubview:copy3];

推荐答案

有多种方法可以实现-

1.您的代码中有一个IBOutlet引用.这是从xcode接口构建器创建的.一旦有了这个,它就很简单-

1.have an IBOutlet reference in your code. This is created from xcode Interface builder. Once you have this then it fairly straight forward -

[iboutlet_foo_object addSubview:copy3];

2. tag您感兴趣的视图.再次标记视图可以从xcode接口构建器或代码中完成.之后-

2.tag the view that you are interested in. Again tagging a view can be done from xcode Interface builder or from code. After that -

Foo *fooObj = [[self superview] viewWithTag:tagInt];
[fooObj addSubview:copy3];

3.最后,您可以遍历超级视图和所有视图中的所有视图.查看哪种类型为Foo-

3.Finally you can iterate through all the views in your superview & see which one is of type Foo -

NSArray *subviews = [[self superview] subviews];
for(UIView *v in subviews)
{
    if(v isKindOfClass:[Foo class])
    {
        [v addSubview:copy3];
        break;
    }
}

希望这些方法可以帮助您...

hope these methods help you...

这篇关于如何在Superview的视图中插入视图? (iOS)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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