用数组创建视图
我想以编程方式创建视图, Matrix: 10X10 = 100 Views 。我已经创建了 IB,但它必须使用 Xcode 进行编程。我该怎么做?
对于一个视图创建这个,对于 10X10 视图我不知道。我怎样才能做到所有观点;
UIView *tempView1 = [[UIView alloc] initWithFrame:CGRectMake(0, 660, 60, 60)];
[self.view addSubview:tempView1];
rd = 0;
gr = 0.5;
bl =0;
tempView1.backgroundColor = [UIColor colorWithRed:rd green:gr blue:bl alpha:1.0];
I want to create views programmatically, Matrix: 10X10 = 100 views . I've created IB but it has to be programmed with Xcode. How can i do this?
For one view create this, for 10X10 views I don't know. How can i do all views;
UIView *tempView1 = [[UIView alloc] initWithFrame:CGRectMake(0, 660, 60, 60)];
[self.view addSubview:tempView1];
rd = 0;
gr = 0.5;
bl =0;
tempView1.backgroundColor = [UIColor colorWithRed:rd green:gr blue:bl alpha:1.0];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这应该可以满足您的需要:
您可能希望将它们放入某种数组中,以便稍后可以访问它们。
如果您希望将 UILabel 之类的组件添加到这些视图中。您将必须使用这些视图的内部坐标系。
This should do the trick for you:
You might want to put them into some sort of array so you can access them at some later point.
If you want components like UILabel to be added to those views. You will have to use the intern coordinate system of those views.
有关更详细的动态布局、行、高度的示例,请查看 我的文章在这里。它不仅展示了如何根据尺寸和屏幕尺寸动态布局框,还展示了动态重新排序的工作原理。
有关更多详细信息,请参阅文章,但关键方法是...
完整的文章 这里。
For an example of more detailed layout, row, height dynamically, check out my article here. It shows how you can not only dynamically layout boxes according to size and screen size but also how dynamic reordering works.
See the article for more details but the key approach is...
Full write-up here.