0

我想知道你如何创建一个以按钮为对象的分页 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);

}

任何教程将不胜感激:)

4

1 回答 1

1

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

替换这个

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];
于 2012-06-13T11:01:03.377 回答