大佬教程收集整理的这篇文章主要介绍了iphone – 如何将UIScrollview与UIPagecontrol结合使用以显示不同的视图?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
- (void)setupPage { scrollView.delegate = self; [self.scrollView setBACkgroundColor:[UIColor clearColor]]; [scrollView setCanCancelContentTouches:NO]; scrollView.inDicatorStyle = UIScrollViewInDicatorStyleWhite; scrollView.clipsToBounds = YES; scrollView.scrollEnabled = YES; scrollView.pagingEnabled = YES; NSUInteger nimages = 0; CGFloat cx = 0; for (; ; nimages++) { NSString *imagename = [NSString StringWithFormat:@"image%d.jpg",(nimages + 1)]; UIImage *image = [UIImage imagenamed:imagename]; if (image == nil) { break; } UIImageView *imageView = [[UIImageView alloc] initWithImage:image]; CGRect rect = imageView.frame; rect.size.height = image.size.height; rect.size.width = image.size.width; rect.origin.x = ((scrollView.frame.size.width - image.size.width) / 2) + cx; rect.origin.y = ((scrollView.frame.size.height - image.size.height) / 2); imageView.frame = rect; [scrollView addSubview:imageView]; [imageView release]; cx += scrollView.frame.size.width; } self.pageControl.@R_618_10793@erOfPages = nimages; [scrollView setContentSize:CGSizeMake(cx,[scrollView bounds].size.height)]; }
UIView *blueView = [[UIView alloc] init]; blueView.frame = CGRectMake(100,500,1024); blueView.BACkgroundColor = [UIColor colorWithRed:164.0/256 green:176.0/256 blue:224.0/256 alpha:1]; [scrollView addSubview:blueView]; [blueView release]; UIView *orangeView = [[UIView alloc] init]; orangeView.frame = CGRectMake(700,1024); orangeView.BACkgroundColor = [UIColor colorWithRed:252.0/256 green:196.0/256 blue:131.1/256 alpha:1]; [scrollView addSubview:orangeView]; [orangeView release];
请注意,我在每个视图的frame.origin中设置x值,以便它们彼此相邻.您还必须使用[scrollView setContentSize:CGSizeMake(1200,1024)]等设置UIScrollView的内容大小;所以它知道它的子视图有多大.
然后,如果您需要控制UIPageControl,您可以将其@R_618_10793@erOfPages设置为2(对于上面的示例scrollview)并更改其currentPage属性.您可以通过实现scrollViewDidEndDecelerating:来实现这一点,这是UIScrollViewDelegate中的一个方法.您可以通过检查其contentOffset.x值来检查scrollview所在的“页面”.
希望这可以帮助!
以上是大佬教程为你收集整理的iphone – 如何将UIScrollview与UIPagecontrol结合使用以显示不同的视图?全部内容,希望文章能够帮你解决iphone – 如何将UIScrollview与UIPagecontrol结合使用以显示不同的视图?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。