为什么将 uilabel 添加到多个子视图不起作用?
比如说,
UILabel *label = [[UILabel alloc] init]; ....
[view1 addSubview:label]; [view2 addSubview:标签];
addSubview 不保留对当前标签的引用吗?也就是说,它有自己的 UILabel 副本,但为什么该标签只显示在视图 2 上?
谢谢。
Say,
UILabel *label = [[UILabel alloc] init];
....
[view1 addSubview:label];
[view2 addSubview:label];
Doesn't addSubview retain a reference to the current label? That is, it has its own copy of the UILabel but why the label only shows up on view 2?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这不起作用,因为视图只能有 1 个超级视图。因此,如果您想在不同视图中拥有同一标签的多个实例,您必须自己创建标签的副本并将其添加到另一个超级视图中。
引用自参考文献:
That does not work because view can have only 1 superview. So if you want to have multiple instances of same label in different views you have to create a copy of your label yourself and add it to another superview.
Quote from reference: