我快疯了!我有以下代码,它没有向 UIScrollView 添加任何内容。在模拟器中渲染时的视图显示为完全白色。
- (void)viewDidLoad
{
[super viewDidLoad];
// add scroll view to the view
self.scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0,self.view.frame.size.height - 200,self.view.frame.size.width,110)];
self.scrollView.contentSize = CGSizeMake(400, 80);
[self.scrollView setScrollEnabled:YES];
[self.scrollView setPagingEnabled:YES];
NSArray *imageNames = [NSArray arrayWithObjects:@"kidontrike_4.png",@"mockup_car2.png",@"mockup_car1.png", nil];
for(NSString *imageName in imageNames)
{
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:imageName]];
imageView.frame = CGRectMake(0, 0, 100, 100);
[self.scrollView addSubview:imageView];
}
[self.view addSubview:self.scrollView];
}
更新 1:
由于某种原因,即使添加带有背景颜色的视图似乎也不会出现。我只看到一个白屏。
@property (nonatomic,weak) UIScrollView *scrollView;
- (void)viewDidLoad
{
[super viewDidLoad];
// add scroll view to the view
self.scrollView = [[UIScrollView alloc] initWithFrame:self.view.frame];
self.scrollView.contentSize = CGSizeMake(80, 80);
[self.scrollView setScrollEnabled:YES];
[self.scrollView setPagingEnabled:YES];
UIView *someView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
[someView setBackgroundColor:[UIColor greenColor]];
[self.scrollView addSubview:someView];
[self.view addSubview:self.scrollView];
}