How can I use UIScrollView?

2019-04-07 17:06发布

How can I use UIScrollView? please give me a simple example with one scrolling image?

7条回答
放荡不羁爱自由
2楼-- · 2019-04-07 17:38

This can be one example. Basically we create a scrollview, set its frame, add content as a subview, and then set the content size. The image (iphone.png) below is bigger than the iphone screen so that we can scroll it.

UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 20, 320, 460)];
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"iphone.png"]];

[scrollView addSubview:imageView];
[imageView release];
scrollView.contentSize = CGSizeMake(imageView.image.size.width, imageView.image.size.height);
[window addSubview:scrollView];
[scrollView release];
查看更多
登录 后发表回答