page enable,

-(IBAction)doImage:(id)sender

{

    CGFloat screenWidth = [UIScreen mainScreen].bounds.size.width;

    NSArray *mArray = @[@"1.jpeg",@"2.jpeg",@"3.jpeg",@"4.jpeg"];

    for (int i = 0; i<mArray.count; i++) {

        NSString *imageName = [mArray objectAtIndex:i];

        UIImage *ig = [UIImage imageNamed:imageName];

        UIImageView *mImageView = [[UIImageView alloc]initWithImage:ig];

        mImageView.frame = CGRectMake(i*screenWidth, 0, screenWidth, 400);

        [self.mScrollview addSubview:mImageView];

    }

    self.mScrollview.contentSize = CGSizeMake(mArray.count*screenWidth, 400);

    self.mScrollview.frame = CGRectMake(0, 0, screenWidth, 400);

    self.mScrollview.delegate = self;

    self.mScrollview.pagingEnabled = YES;

    self.mPageControl.currentPage = 0;

    self.mPageControl.numberOfPages = mArray.count;

    [self.mPageControl addTarget:self action:@selector(changePage:) forControlEvents:UIControlEventValueChanged];

    

}

 

 

-(void)scrollViewDidScroll:(UIScrollView *)scrollView

{

    CGFloat pageWidth = scrollView.frame.size.width;

    int page = floor((scrollView.contentOffset.x - pageWidth / 2) / pageWidth) + 1;

    self.mPageControl.currentPage = page;

    

}

 

- (void)changePage:(id)sender

{

    int page = self.mPageControl.currentPage;

    CGRect frame = self.mScrollview.frame;

    frame.origin.x = frame.size.width * page;

    frame.origin.y = 0;

    [self.mScrollview scrollRectToVisible:frame animated:YES];

}

posted @ 2015-04-12 14:29  路在脚下,  阅读(115)  评论(0编辑  收藏  举报