Xcode,UIscrollView和分页 [英] Xcode, UIscrollView and pagination
本文介绍了Xcode,UIscrollView和分页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是一个初学者,我需要知道如何将UIScrollView放在多个页面中.这些页面应包含交互元素,例如按钮,视频以及文本和图像.任何与教程的链接或您可以给我的一些线索,我将不胜感激.
I am a beginner, I need to know how I can put in a UIScrollView multiple pages. These pages should contain interactive elements such as buttons,video and also text and images. I would appreciate any link to a tutorial or some clue that you could give me.
致谢.
推荐答案
- 将滚动视图的
pagingEnabled
属性设置为YES
- 如果要水平分页,请使滚动视图的
contentSize
属性X * width
宽,如果要垂直分页,请使"X *高度"高. - 通过为每个页面"添加子视图,并为每个页面添加正确的偏移量("X *宽度"或"X *高度",取决于水平/垂直).ž
- set your scroll view's
pagingEnabled
property toYES
- make your scroll view's
contentSize
propertyX * width
wide if you want horizontal paging or `X * height' tall if you want vertical paging. - add subview to each "page" by adding them with the right offset for each page (`X * width' or 'X * height' depending on horizontal/vertical).ž
X是从0开始的页数.
X is a number of pages, starting with 0.
这是一个具有5个水平页面的示例.
Here is a sample with 5 horizontal pages.
int numberOfPages = 5;
UIScrollView *someScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 100)];
someScrollView.pagingEnabled = YES;
someScrollView.contentSize = CGSizeMake(numberOfPages * someScrollView.frame.size.width, someScrollView.frame.size.height);
[self.view addSubview:someScrollView];
[someScrollView release];
for (int i = 0; i < numberOfPages; i++) {
UILabel *tmpLabel = [[UILabel alloc] initWithFrame:CGRectMake(i * someScrollView.frame.size.width + 20,
20,
someScrollView.frame.size.width - 40,
20)];
tmpLabel.textAlignment = UITextAlignmentCenter;
tmpLabel.text = [NSString stringWithFormat:@"This is page %d", i];
[someScrollView addSubview:tmpLabel];
[tmpLabel release];
}
这篇关于Xcode,UIscrollView和分页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文