UIScrollView显示为空白屏幕

时间:2014-12-23 23:29:51

标签: ios objective-c uiviewcontroller uiscrollview scroll-paging

我正在尝试制作可以翻阅不同彩色背景的滚动视图。截至目前,当我尝试进入滚动视图时,背景不显示,只留下空白屏幕,没有滚动功能。我花了几个小时在网上寻找解决方案,但似乎没有任何效果。这是我的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]; 
}

0 个答案:

没有答案