滚动视图中的多个图像 [英] Multiple image in scrollview
本文介绍了滚动视图中的多个图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有 12 张图像,我想在 UIScrollview
中显示这些图像,其中有 4 行,每行有 3 张图像.
I have 12 images and i want to display this images in UIScrollview
with 4 rows where each rows have 3 images.
推荐答案
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++;
}
这篇关于滚动视图中的多个图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文