问题
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