UIPageControl 不显示
Posted
技术标签:
【中文标题】UIPageControl 不显示【英文标题】:UIPageControl is not Displayed 【发布时间】:2010-07-20 06:53:31 【问题描述】:我使用以下来显示滚动视图和页面控件
scrollView=[[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 179)];
pageControl=[[UIPageControl alloc] initWithFrame:CGRectMake(0, 179, 320, 20)];
scrollView.delegate = self;
[scrollView setBackgroundColor:[UIColor blackColor]];
[scrollView setCanCancelContentTouches:NO];
scrollView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
scrollView.clipsToBounds = YES;
scrollView.scrollEnabled = YES;
scrollView.pagingEnabled = YES;
int index=[[self._parameters objectForKey:@"index"] intValue];
NSString *imageNamePrefix=[[activeAppIdList objectAtIndex:index] objectForKey:@"AppID"];
int noOfScreenShot=[[[activeAppIdList objectAtIndex:index] objectForKey:@"NoOfScreenShot"] intValue];
CGFloat cx = 0;
for (int j=1;j<=noOfScreenShot ; j++)
UIImage *image =[[UIImage alloc] init];
image= [self loadImage:[[NSString alloc]initWithFormat:@"%@_%d.jpg",imageNamePrefix,j]];
if (image == nil)
NSString *urlString = [[NSString alloc]initWithFormat:@"http://localhost/MoreApp/images/%@_%d.jpg",imageNamePrefix,j];
NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:urlString]];
UIImage *temp=[[UIImage alloc]initWithData:imageData] ;
[self saveImage:temp withName:[[NSString alloc]initWithFormat:@"%@_%d.jpg",imageNamePrefix,j]];
image = temp;
[temp release];
[urlString release];
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
[image release];
imageView.frame = CGRectMake(cx,0,scrollView.frame.size.width,scrollView.frame.size.height);
[scrollView addSubview:imageView];
[imageView release];
cx += scrollView.frame.size.width;
NSLog(@"No Of pages..%d",noOfScreenShot);
pageControl.numberOfPages = noOfScreenShot;
pageControl.currentPage = 0;
scrollView.contentSize = CGSizeMake(cx,scrollView.frame.size.height);
NSLog(@"Width:%f",scrollView.frame.size.width);
[ refToSelf.instructionView addSubview:scrollView];
[ refToSelf.instructionView addSubview:pageControl];
[scrollView release];
[pageControl release];
scrollview 没问题,但是 pagecontroll 没有显示... 可以帮忙吗??
【问题讨论】:
如果您解决了问题,请发布解决方案并标记为已回答。 【参考方案1】:如果页面控件和容器的背景颜色相同(默认为白色)页面控件将不可见。
【讨论】:
是的......这是一个错误......背景和页面控件的颜色相同......所以它不可见......【参考方案2】:对于发现此问题的任何人,您可能犯的另一个愚蠢错误是未在 UIPageControl
上设置 numberOfPages
属性,这也会导致它不显示。
【讨论】:
【参考方案3】:我的错误同样令人讨厌 - 在 3.5 英寸视图中使用故事板进行开发,并在模拟器上构建在 4 英寸设备上,因此它在屏幕外。傻!
【讨论】:
以上是关于UIPageControl 不显示的主要内容,如果未能解决你的问题,请参考以下文章