1:假如有6个图片:那个,Scrollview的大小加 7 个图片的大小
2:
//ImageScrollView;
UIScrollView *imageScroll = [[UIScrollView alloc]initWithFrame:CGRectMake(, , , )];
imageScroll.bounces = YES;
imageScroll.pagingEnabled = YES;
imageScroll.userInteractionEnabled = YES;
imageScroll.showsVerticalScrollIndicator = NO;
imageScroll.showsHorizontalScrollIndicator = NO;
imageScroll.delegate = self;
imageScroll.contentSize = CGSizeMake( * , );
[theScrollView addSubview:imageScroll];
[imageScroll release]; //加上图片;
for (int i = ; i < ; i++) {
UIImageView *aImageView = [[UIImageView alloc]initWithFrame:kCR( + *i, , , )];
aImageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"keenLC%d.jpg",i+]];
if (i==) {
aImageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"keenLC%d.jpg",]];
} [imageScroll addSubview:aImageView];
[aImageView release]; }
//图片数字label
imageNumLabel = [[UILabel alloc]initWithFrame:kCR(, imageScroll.bottom - , , )];
imageNumLabel.text = @"1/6";
imageNumLabel.textAlignment = NSTextAlignmentCenter;
imageNumLabel.textColor = [UIColor whiteColor];
imageNumLabel.backgroundColor = [UIColor clearColor];
[theScrollView addSubview:imageNumLabel];
[imageNumLabel release];
3: ScrollView的代理
#pragma mark Scroll delegate
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView;{
int currentPage = floor((scrollView.contentOffset.x - scrollView.frame.size.width / ) / scrollView.frame.size.width) + ;
imageNumLabel.text = [NSString stringWithFormat:@"%d/6",currentPage + ];
//imageScroll.transform = CGAffineTransformMakeScale(1,1);
if (currentPage==) {
[scrollView setContentOffset:CGPointMake(, ) animated:NO];
imageNumLabel.text = [NSString stringWithFormat:@"%d/6",];
}
}