1

我有一个带有页面的滚动视图,它使用图像来显示不同的页面,我希望将按钮放在不同的页面上,但我不太确定如何去做。

这是我当前的代码:

- (void)viewDidLoad
{
    [super viewDidLoad];

    // add the first image (image1) into the last position
    [self addImageWithName:@"image1.jpg" atPosition:0];

    scrollView.contentSize = CGSizeMake(2272, 320);
    [scrollView scrollRectToVisible:CGRectMake(568,0,0,320) animated:NO];

    // add the last image (image4) into the first position
    [self addImageWithName:@"image4.jpg" atPosition:5];

    // add all of the images to the scroll view
    for (int i = 1; i < 4; i++) {
        [self addImageWithName:[NSString stringWithFormat:@"image%i.jpg",i] atPosition:i];
    }
}
-(void)viewDidAppear:(BOOL)animated {
    [self.navigationController setNavigationBarHidden:NO animated:YES];
}
- (void)addImageWithName:(NSString*)imageString atPosition:(int)position {
    // add image to scroll view
    UIImage *image = [UIImage imageNamed:imageString];
    UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
    imageView.frame = CGRectMake(position*568, 0, 568, 320);
    [scrollView addSubview:imageView];
}
4

1 回答 1

0

您可以参考下面的链接以获得相同的功能

http://eureka.ykyuen.info/2010/05/22/iphone-uiscrollview-with-paging-example/

您可以添加按钮而不是标签。

于 2012-11-16T13:01:37.683 回答