图书的摆放

一、

e.g.:


图书的摆放_第1张图片
1:1


图书的摆放_第2张图片
1:2
图书的摆放_第3张图片
1:3


图书的摆放_第4张图片
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);

你可能感兴趣的:(图书的摆放)