scrollview背景

 

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

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

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

 

滑动属性:

 _scrollView.pagingEnabled = YES; //只能按页滑动,设置为NO时可以连续滑动
   _scrollView.bounces = YES; //可以打开顶部的间隔,松开后,又弹回去了。 如果bounds设置为NO,则打不开下拉刷新

 

 

- (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;

    
    
}

IOS开发: 为UIImageView添加点击事件

 

posted @ 2014-10-14 17:44  米粥米  阅读(666)  评论(0编辑  收藏  举报