标签:
用循环构建多视图的相关代码
- (viod) viewDidLoad
{
[super loadView];
UIView *view = [[[UIView alloc] init] autorelease];
self.view = view;
NSInteger line = 3;
NSInteger row = 3;
CGFloat width = 80;
CGFloat height = 80;
//获取第一个视图的x,y坐标
CGFloat x = (self.view.bounds.size.width - width * row) / (row + 1);
CGFloat y = (self.view.bounds.size.height - height * line) / (line + 1);
for (NSInteger i = 0; i < line * row; i++)
{
//计算每一个视图坐标
CGFloat x1 = width + (width + x) * (i % line);
CGFloat y1 = height + (height + y) * (i / row);
UIView *newView = [[[UIView alloc] initWithFrame:CGRectMake(x1, y1, width, height)] autorelease];
newView.backgoundColor = [UIColor cyanColor];
[view addSubView:newView];
}
}
标签:
原文地址:http://www.cnblogs.com/tang910103/p/5055871.html