- (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.numberOfPages = nimages; [scrollVIEw setContentSize:CGSizeMake(cx,[scrollVIEw bounds].size.height)];}解决方法 前几天我正在试验这个.我仍然习惯使用UIScrollVIEw,但是这里是如何为UIScrollVIEw添加视图的:
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,您可以将其numberOfPages设置为2(对于上面的示例scrollvIEw)并更改其currentPage属性.您可以通过实现scrollVIEwDIDEndDecelerating:来实现这一点,这是uiscrollviewdelegate中的一个方法.您可以通过检查其contentOffset.x值来检查scrollvIEw所在的“页面”.
希望这可以帮助!
总结以上是内存溢出为你收集整理的iphone – 如何将UIScrollview与UIPagecontrol结合使用以显示不同的视图?全部内容,希望文章能够帮你解决iphone – 如何将UIScrollview与UIPagecontrol结合使用以显示不同的视图?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)