码迷,mamicode.com
首页 > 其他好文 > 详细

scrollview背景

时间:2014-10-14 21:03:19      阅读:157      评论:0      收藏:0      [点我收藏+]

标签:des   blog   color   io   os   ar   for   sp   div   

bubuko.com,布布扣

 

当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背景

标签:des   blog   color   io   os   ar   for   sp   div   

原文地址:http://www.cnblogs.com/dqxu/p/4024921.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!