用UICellectionView也可以搞定,根據(jù)需求來選擇吧:)
在一個view中根據(jù)imgArray中圖片數(shù)量,動態(tài)創(chuàng)建多個UIImageView展示圖片,一行展示三個圖片,當(dāng)多于三個時,圖片多一行,整個view也要增加高度。
//取屏幕寬高
floatwidth = [UIScreen mainScreen].bounds.size.width;
chooseImageView = [[UIViewalloc] init];NSArray*imgArray = [[NSArrayalloc] initWithObjects:@"1_leirobin.jpg",@"1_leirobin.jpg",@"1_leirobin.jpg",@"1_leirobin.jpg",@"1_leirobin.jpg",nil];NSIntegerpicCount = [imgArray count];//定義每個cell圖片for(inti=0;i
imageCell.image= [UIImageimageNamed:[NSStringstringWithFormat:@"%@",[imgArray objectAtIndex:i]]];//每當(dāng)?shù)?個圖片時,增加一行,增加整個view的高度if(i%3==0) {
[chooseImageView setFrame:CGRectMake(0,100, width, chooseImageView.frame.size.height+width/3+20)];
}
[chooseImageView addSubview:imageCell];
}
[self.viewaddSubview:chooseImageView];