UIPageControl is not Displayed

≡放荡痞女 提交于 2019-12-08 15:00:23

问题


I use the following to display scrollview and 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 is ok but pagecontroll didn't showed... can help??


回答1:


If the page control's and container's background color is the same (by default white) page control won't be visible.




回答2:


For anyone who finds this, another silly mistake you can make is to not set the numberOfPages attribute on the UIPageControl, which will also cause it to not display.




回答3:


My mistake was equally annoying - developing with storyboard in 3.5 inch view, and built on 4 inch device on simulator so it was offscreen. Silly!



来源:https://stackoverflow.com/questions/3287657/uipagecontrol-is-not-displayed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!