您的位置:首页 > 移动开发 > IOS开发

IOS 多行多列加载ImageView

2015-09-21 00:05 246 查看
用宏定义行高,行宽,行数,列数及间隔

#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];

}

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: