Adding UIImageViews to UIScrollView

十年热恋 提交于 2019-12-30 18:55:45

问题


I am currently researching ways of adding several UIImageView to a single UIScrollView. The UIScrollView will be 1.5 times the size of any one of the UIImageViews. I want to create a scrolling effect for browsing through some small images in an iPad application. Does anyone know how to achieve this?


回答1:


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];



回答2:


If you want zoom and everything:

http://developer.apple.com/library/ios/#samplecode/PhotoScroller/Introduction/Intro.html%23//apple_ref/doc/uid/DTS40010080

If you just want a paging scrollview:

http://developer.apple.com/library/ios/#samplecode/PageControl/Introduction/Intro.html%23//apple_ref/doc/uid/DTS40007795



来源:https://stackoverflow.com/questions/3777364/adding-uiimageviews-to-uiscrollview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!