繁体   English   中英

带按钮的UIScrollView分页

[英]UIScrollView paging with buttons

我想知道如何创建带有按钮作为对象的页面UIScrollView?

到目前为止,我已经想出了用图像代替类似的UIScrollView的方法,看起来像这样:

    - (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

    NSArray *pictures = [NSArray arrayWithObjects: [UIImage imageNamed:@"nr1"], [UIImage imageNamed:@"nr2"], nil];


    for (int i = 0; i < pictures.count; i++) {
        CGRect frame;
        frame.origin.x = self.scrollView.frame.size.width * i;
        frame.origin.y = 0;
        frame.size = self.scrollView.frame.size;

        UIImageView *subview = [[UIImageView alloc] initWithFrame:frame];
        subview.image = [pictures objectAtIndex:i];
        [self.scrollView addSubview:subview];
    }

    self.scrollView.contentSize = CGSizeMake(self.scrollView.frame.size.width * pictures.count, self.scrollView.frame.size.height);

}

任何教程,将不胜感激:)

您将只添加按钮而不是图像

取代这个

UIImageView *subview = [[UIImageView alloc] initWithFrame:frame];
subview.image = [pictures objectAtIndex:i];
[self.scrollView addSubview:subview];

UIButton *subview = [UIButton buttonWithType:UIButtonTypeRoundedRect];
subview.frame = frame;
[subview setTitle:@"Test" forState:UIControlStateNormal];
[self.scrollView addSubview:subview];

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM