带有页面的滚动视图中的“按钮”

时间:2012-11-16 00:09:21

标签: objective-c

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

这是我目前的代码:

- (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];
}

1 个答案:

答案 0 :(得分:0)

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

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

您可以添加按钮代替标签。