UIPageControl未显示

时间:2010-07-20 06:53:31

标签: iphone objective-c uipagecontrol

我使用以下内容显示scrollview和pagecontrol

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没有显示... 可以帮忙??

3 个答案:

答案 0 :(得分:29)

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

答案 1 :(得分:12)

对于发现此问题的任何人,您可以犯的另一个愚蠢的错误是不在numberOfPages上设置UIPageControl属性,这也会导致它无法显示。

答案 2 :(得分:2)

我的错误同样令人讨厌 - 在3.5英寸视图中使用故事板进行开发,并在模拟器上构建4英寸设备,因此它在屏幕外。傻!