九宫格
NSInteger count = self.subviews.count;
CGFloat padding = 10;
NSInteger totalCol = 3;
CGFloat x = 0;
CGFloat y = 0;
CGFloat wh = (self.bounds.size.width - (totalCol + 1) * padding) / totalCol;
;
NSInteger col = 0;
NSInteger row = 0;
for (NSInteger i = 0; i < count; i ++) {
col = i % totalCol;
x = col * (padding + wh);
row = i / totalCol;
y = row * (padding + wh);
UIImageView *imageV = self.subviews[i];
imageV.frame= CGRectMake(x, y, wh, wh);
}
分页公式
NSInteger totalCol = (count + rowMaxTotal - 1) / rowMaxTotal; //总共行数
网友评论