九宫格算法

2017-04-30  本文已影响43人  EdenChow
九宫格
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;  //总共行数
上一篇下一篇

猜你喜欢

热点阅读