Add 10 different UIImages in UIScrollView

不羁的心 提交于 2019-12-04 10:10:38

The idea is basically simple. Let's assume you want to place 3 images in UIScrollView. Each of images is 300x300. In this case you'll have scroll view with frame:

scrollView.contentSize = CGSizeMake(image.size.width,900);

For every image you must have it's UIImageView with proper frame:

imgView1 = [[UIImageView alloc] initWithFrame:CGRectMake(xOrigin, 0, 300, 300)];
imgView2 = [[UIImageView alloc] initWithFrame:CGRectMake(xOrigin, 300, 300, 300)];
imgView3 = [[UIImageView alloc] initWithFrame:CGRectMake(xOrigin, 600, 300, 300)];
imgView1.image = [UIImage imageNamed:@"ProperName.png"];
...

(pay attention to the yOrigin (2nd value in CGRectMake)) and then as you did:

[scrollView addSubview:imgView1];
[scrollView addSubview:imgView2];
[scrollView addSubview:imgView3];
[imgView1 release];
[imgView2 release];
[imgView3 release];

Of course, it's a brief code, you'll optimize it ;)

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