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添加点击事件

 

转载于:https://www.cnblogs.com/dqxu/p/4024921.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值