滚动视图显示,没有任何可见的视图。视图移动正常,页面控件正常工作。当我更改滚动条背景时,一切正常。没有显示“不同颜色”的视图。不知道出了什么问题。谢谢您的帮助
-(void)viewDidLoad {
[super viewDidLoad];
CGRect frame = CGRectMake(0, 215, WIDTH_OF_IPHONE, HEIGHT_OF_SCROLLER);
int numOfPhotos = 6;
scrollViewer = [[UIScrollView alloc] initWithFrame:frame];
scrollViewer.contentSize = CGSizeMake((WIDTH_OF_IPHONE*numOfPhotos), HEIGHT_OF_SCROLLER);
scrollViewer.pagingEnabled = YES;
//scrollViewer.backgroundColor = [UIColor lightGrayColor];
[scrollViewer setDelegate:self];
int i = 0;
while (i < numOfPhotos){
CGRect frameOfView = CGRectMake((i*320), 215, 320, HEIGHT_OF_SCROLLER);
UIView *photoFrame = [[UIView alloc] initWithFrame:frameOfView];
if (i == 0){
photoFrame.backgroundColor = [UIColor redColor];//colorWithPatternImage:image1];
NSLog(@"colour was selected");
}else if (i==1){
photoFrame.backgroundColor = [UIColor blueColor];//colorWithPatternImage:image2];
}else if (i==2){
photoFrame.backgroundColor = [UIColor purpleColor];//colorWithPatternImage:image3];
}else if (i==3){
photoFrame.backgroundColor = [UIColor orangeColor];//colorWithPatternImage:image4];
}else if (i==4){
photoFrame.backgroundColor = [UIColor magentaColor];//colorWithPatternImage:image5];
}else{
photoFrame.backgroundColor = [UIColor greenColor];//colorWithPatternImage:image6];
}
[scrollViewer addSubview:photoFrame];
//[photoFrame release];
photoFrame = NULL;
i++;
}
pageControl = [[UIPageControl alloc] initWithFrame:CGRectMake(0, 0, WIDTH_OF_IPHONE, 15)];
pageControl.center = CGPointMake(scrollViewer.center.x, (208+HEIGHT_OF_SCROLLER));
[pageControl setNumberOfPages:numOfPhotos];
[pageControl addTarget:self action:@selector(pageSwiped:) forControlEvents:UIControlEventValueChanged];
[self.view addSubview:scrollViewer];
[self.view addSubview:pageControl];
我的 .H 文件看起来像这样
@interface HomePage : UIViewController <UIActionSheetDelegate, UIScrollViewDelegate> {
IBOutlet UIScrollView *scrollViewer;
UIPageControl *pageControl;
BOOL pageControlUsed;
}
@end