首页 > 代码库 > 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背景
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。