Xcode、UIscrollView 和分页 [英] Xcode, UIscrollView and pagination

查看:22
本文介绍了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.

问候.

推荐答案

  1. 将滚动视图的 pagingEnabled 属性设置为 YES
  2. 如果您想要水平分页,则将滚动视图的 contentSize 属性设置为 X * width 宽,如果您想要垂直分页,请将其设置为X * height".
  3. 将子视图添加到每个页面",方法是为每个页面添加正确的偏移量(`X * width' 或 'X * height',取决于水平/垂直).ž
  1. set your scroll view's pagingEnabled property to YES
  2. make your scroll view's contentSizeproperty X * width wide if you want horizontal paging or `X * height' tall if you want vertical paging.
  3. 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆