代码改变世界

IOS 多行多列加载ImageView

2015-09-21 00:05  一树一菩提  阅读(278)  评论(0)    收藏  举报

用宏定义行高,行宽,行数,列数及间隔

#define ROW_COUNT  5

#define COLUMN_COUNT 3

#define ROW_HEIGHT 100

#define ROW_WIDTH ROW_HEIGHT

#define CELL_SPACING 10

 

 

 

- (void)viewDidLoad {

    [super viewDidLoad];

    [self layoutUI];

 

}

-(void)layoutUI{

  _imageViews = [NSMutableArray array];

    //5行3列图片数据放到可变数组中

    for (int r=0; r<ROW_COUNT; r++) {

        for (int c=0; c<COLUMN_COUNT; c++) {

            UIImageView *imageView=[[UIImageView alloc]initWithFrame:CGRectMake(c*ROW_WIDTH+(c*CELL_SPACING), r*ROW_HEIGHT+(r*CELL_SPACING                           ), ROW_WIDTH, ROW_HEIGHT)];

            imageView.contentMode=UIViewContentModeScaleAspectFit;

            [self.view addSubview:imageView];

            [_imageViews addObject:imageView];

            

        }

    }

 

 

 

    }