首页 > 代码库 > scrollview背景

scrollview背景

 

当scrollview不设置背景色时,拖动scrollview上的内容,边界显示view的背景色。

当scrollview设置背景色时,拖动scrollview上的内容,边界显示scrollview的背景色

 

用两种颜色时,可以在scrollview上再添加一层,如黄色的view。

- (void)viewDidLoad{    [super viewDidLoad];	// Do any additional setup after loading the view, typically from a nib.    //CGFloat w = self.view.frame.size.width;    //CGFloat h = self.view.frame.size.height;    int w = self.view.bounds.size.width;    int h = self.view.bounds.size.height;        self.view.backgroundColor = [UIColor redColor];            _scrollView = [[UIScrollView alloc]initWithFrame:self.view.frame];    _scrollView.backgroundColor = [UIColor blueColor];        [self.view addSubview:_scrollView];                UIView *view = [[UIView alloc]initWithFrame:self.view.frame];    [_scrollView addSubview: view];        view.backgroundColor = [UIColor yellowColor];        for(int i = 0;i< kCount;i++)    {                NSString *name = [NSString stringWithFormat:@"%02d.jpg",i+1];        UILabel *label = [[UILabel alloc] init];        label.frame = CGRectMake(i*w, 0, w, h);        label.text = name;        [view addSubview:label];                    }            _scrollView.userInteractionEnabled = YES;        _scrollView.contentSize = CGSizeMake(kCount*w, 800);// height == 0 代表 禁止垂直方向滚动    _scrollView.scrollEnabled = YES;    _scrollView.pagingEnabled = YES;        _scrollView.delegate = self;        }

 

scrollview背景