私はこれに夢中になっています!次のコードがあり、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];
}