UIPageControl未显示

13
我使用以下代码来展示滚动视图和页面控制器。
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没问题,但pagecontrol没有显示出来...能帮忙吗?


如果您解决了您的问题,请发布解决方案并将其标记为已回答。 - Tsimmi
3个回答

30

如果页面控件和容器的背景颜色相同(默认为白色),则页面控件将不可见。


1
是的...这是一个错误...背景和页面控件颜色相同...所以它不可见... - Rony

14
对于任何发现此问题的人,还有一个愚蠢的错误是没有设置 UIPageControl 上的 numberOfPages 属性,这也会导致它无法显示。

2

我犯了一个同样令人恼火的错误——在3.5英寸视图下使用storyboard进行开发,然后在模拟器上构建4英寸设备,导致屏幕外。太傻了!


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接