1

我正在尝试制作一个可以翻阅不同颜色背景的滚动视图。截至目前,当我尝试进入该滚动视图时,没有显示背景,只留下一个空白屏幕并且没有滚动功能。我花了几个小时在网上寻找解决方案,但似乎没有任何效果。这是我的 ImageViewController 类的实现:

- (void)loadView
{
   [super loadView];
    NSArray *colors = [NSArray arrayWithObjects:[UIColor redColor], [UIColor greenColor], [UIColor blueColor], nil];
    for (int i = 0; i < colors.count; i++) {
        CGRect frame;
        frame.origin.x = self.scrollView.frame.size.width * i;
        frame.origin.y = 0;
        frame.size = self.scrollView.frame.size;

        UIView *subview = [[UIView alloc] initWithFrame:frame];
        subview.backgroundColor = [colors objectAtIndex:i];
        [self.scrollView addSubview:subview];
    }

    self.scrollView.contentSize = CGSizeMake(self.scrollView.frame.size.width * colors.count, self.scrollView.frame.size.height);
    [self.view addSubview:scrollView]; 
}
4

0 回答 0