- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    _scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 340, 460)];
    _scrollView.backgroundColor = [UIColor whiteColor];
    _scrollView.delegate = self;
    _scrollView.pagingEnabled = YES;
    _scrollView.tag = INT_MAX;
    _scrollView.showsHorizontalScrollIndicator = NO;

    _scrollView.contentSize = CGSizeMake(340 * 4, 460);
    [self.view addSubview:_scrollView];

    int _x = 0;

    for (int index = 0; index < 4; index++) {
        UIImageView *imgScrollView = [[UIImageView alloc] initWithFrame:CGRectMake(0+_x, 0, 320, 460)];
        imgScrollView.tag = index;
        NSString *imgName = [NSString stringWithFormat:@"%d.JPG", index + 1];
        imgScrollView.image = [UIImage imageNamed:imgName];
        [_scrollView addSubview:imgScrollView];
        _x += 340;

    }

    UIPageControl *pageControl = [[UIPageControl alloc] initWithFrame:CGRectMake(0, 180, 320, 50)];
    pageControl.numberOfPages = 4;
    pageControl.tag = 101;
    [self.view addSubview:pageControl];
    [pageControl release];
}

- (void) scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
    int current = scrollView.contentOffset.x / 320;
    UIPageControl *pageControl = (UIPageControl *)[self.view viewWithTag:101];
    pageControl.currentPage = current;

}
04-14 00:39