将UIImageViews添加到UIScrollView

时间:2010-09-23 10:21:38

标签: iphone objective-c cocoa-touch

我目前正在研究向单个UIImageView添加多个UIScrollView的方法。 UIScrollView的大小是UIImageViews中任意一个的1.5倍。我想创建一个滚动效果来浏览iPad应用程序中的一些小图像。有谁知道如何实现这个目标?

2 个答案:

答案 0 :(得分:11)

UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(/*FRAME*/)]; // this makes the scroll view - set the frame as the size you want to SHOW on the screen
[scrollView setContentSize:CGSizeMake(/*SIZE OF THE CONTENT*/)]; // if you set it to larger than the frame the overflow will be hidden and the view will scroll

/* you can do this bit as many times as you want... make sure you set each image at a different origin */
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"/*IMAGE*/"]]; // this makes the image view
[imageView setFrame:CGRectMake(/*SET AS 2/3 THE SIZE OF scrollView AND EACH IMAGE NEXT TO THE LAST*/)]; // this makes the image view display where you want it and at the right size
[scrollView addSubview:imageView]; // this adds the image to the scrollview
/* end adding image */

[self.view addSubview:scrollView];

答案 1 :(得分:1)