我有12张图片,我想在UIScrollview
中以4行显示这些图片,每行有3张图片。
答案 0 :(得分:3)
x=0;
y=0;
UIScrollView *scroller=[[UIScrollView alloc]init];
scroller.frame=CGRectMake(20.0, 10.0, 250.0, 250.0);
// WithFrame:CGRectMake(6, 0, 250, 250)];
scroller.delegate=self;
[self.view addSubview:scroller];
[scroller setContentSize:(CGSizeMake(300,(([mainArray count]+3-1)/3)*20))];
//main array means ur image array
for (int i=1; i<[mainArray count]+1; i++)
{
if (x%3==0)
{
x=0;
y++;
}
UIImageView *imgFirstRowActivitySelector=[[UIImageView alloc]initWithFrame:CGRectMake(x*60, y*60, 50, 50)];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
dispatch_async(dispatch_get_main_queue(), ^{
// imgFirstRowActivitySelector.image=[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",[mainArray objectAtIndex:i-1]]]]];
or
// imgFirstRowActivitySelector.image=[UIImage imagenamed:@"%@",[mainArray objectAtIndex:i-1]];
imgFirstRowActivitySelector.userInteractionEnabled=YES;
imgFirstRowActivitySelector.contentMode = UIViewContentModeScaleToFill;
imgFirstRowActivitySelector.tag=i-1;
});
});
[scroller addSubview:imgFirstRowActivitySelector];
imgFirstRowActivitySelector=nil;
x++;
}
答案 1 :(得分:0)
尝试使用UICollectionView它是UIScrollView的子类。
答案 2 :(得分:0)
可以在滚动视图中显示12个图像,但我建议您使用UICollectionView。它使用与UITableView
相同的概念,并且将消除管理每个图像的帧的任务。