一、
e.g.:
1:1 1:2 1:3 2排 9张图片NSInteger count = 4;//代表图片的张数
CGFloat viewWH = self.view.bounds.size.width;
NSInteger row = count / 3;
CGFloat imageWH = viewWH / (row ? 3 : count);
UIView * backView = [[UIView alloc] initWithFrame:CGRectMake(0, 100, viewWH, 0)];
backView.backgroundColor = [UIColor blackColor];
[self.view addSubview:backView];
UIView * view;
for (NSInteger i = 0; i < count; i++) {
CGFloat viewX = i % 3 * imageWH;
CGFloat viewY = i / 3 * imageWH;
view = [[UIView alloc] initWithFrame:CGRectMake(viewX, viewY, imageWH, imageWH)];
view.backgroundColor = [UIColor colorWithRed:arc4random()%256 / 255.0 green:arc4random()%256 / 255.0 blue:arc4random()%256 / 255.0 alpha:1];
[backView addSubview:view];
}
backView.frame = CGRectMake(0, 100, viewWH, view.frame.origin.y + view.frame.size.height);
网友评论