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 没问题,但 pagecontroll 没有显示...可以帮忙吗?

4

3 回答 3

30

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

于 2010-11-22T13:00:42.403 回答
14

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

于 2014-05-27T18:03:29.523 回答
2

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

于 2014-02-25T13:40:49.357 回答