1.首先在控制器定義 常量
#define PIC_WIDTH 20
#define PIC_HEIGHT 50
#define COL_WIDTH 20
2.遍歷初始化控件
- (void)test
{
//for循環(huán)添加控件
for (int i = 0; i < pictureArr.count; i++) {
//創(chuàng)建圖片
UIImageView *imageView = [[UIImageView alloc] init];
imageView.image = [UIImage imageNamed:pictureArr[i]];
[self.view addSubview:imageView];
//計(jì)算行
NSInteger row = i / COL_COUNT;
//計(jì)算列
NSInteger col = i % COL_COUNT;
//間距
CGFloat margain = (self.view.bounds.size.width - (PIC_WIDTH * COL_COUNT)) / (COL_COUNT+1);
//X
CGFloat picX = margain +(PIC_WIDTH + margain) * col;
//Y
CGFloat picY = margain +(PIC_HEIGHT + margain) * row;
//設(shè)置frame
imageView.frame = CGRectMake(picX, picY, PIC_WIDTH, PIC_HEIGHT);
}
}
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者