我正在开发一个使用滚动视图的图片库。我想知道我可以在滚动视图上设置缩略图。我的意思是每行只需要4个缩略图。第五个在第二排。
谢谢..
发布于 2011-05-05 19:45:02
试试下面这段代码,它会将图片添加到滚动视图中:
for (int i=0; i<rand; i++)
    {
        galleryButton = [[UIButton alloc] init];
        galleryButton.tag = i;
        if (count ==3) {
            y=30;
            x+=105;
            count=0;
        }
        galleryButton.frame = CGRectMake(x, y, 85, 85);//x=0
        [galleryButton addTarget:self action:@selector(viewButtonPushed:) forControlEvents:UIControlEventTouchUpInside];
        y+=90;
        UIImage *image = [UIImage imageNamed:[imageArray objectAtIndex:i]];
        NSLog(@"------%@",[imageArray objectAtIndex:i]);
        UIImageView *btnImg = [[UIImageView alloc]initWithFrame:CGRectMake(0,0,97,85)];        
        [btnImg setImage:image];
        count++;
        [galleryButton addSubview:btnImg];
        [imageScroll addSubview:galleryButton];
    }
}在viewdidload中使用代码来设置scrollview属性:
[imageScroll setContentSize:CGSizeMake(1920,282)];
imageScroll.pagingEnabled =NO; 
[imageScroll setScrollEnabled:YES];
imageScroll.showsHorizontalScrollIndicator=NO;
[imageScroll setCanCancelContentTouches:NO];
imageScroll.clipsToBounds = YES;发布于 2011-05-05 19:43:28
UIScrollView基本上是一个UIView,所以可以用UIView完成的任何事情都可以在scrollView中完成。
据我所知,你希望你的拇指指甲是这样的
1 2 3 4
5 6 7 8
这不是问题
如果你想在一个页面上显示四个缩略图,而在其他页面滚动中显示另外四个缩略图,同样也是可以的。
https://stackoverflow.com/questions/5897013
复制相似问题