UITableView上拉下滑时显示不同背景色的技巧

如下图,在上滑列表时背景显示白色,下拉时显示蓝色。

更改tableView的背景色、或者headerView等均达不到满意效果。

可以给tableview添加一个backgroundView,然后在此上添加多个UiView设置不同颜色达到效果。代码如下:

UIView *tableBackgroundView =[[UIView alloc]initWithFrame:_tableView.frame];

        tableBackgroundView.backgroundColor =[UIColor whiteColor];

        UIView *bk0 =[[UIView alloc]initWithFrame:CGRectMake(0, 0, _tableView.frame.size.width, _tableView.frame.size.height * 0.5)];

        bk0.backgroundColor =[UIColor blueColor];

        [tableBackgroundView addSubview:bk0];

        UIView *bk1 =[[UIView alloc]initWithFrame:CGRectMake(0, _tableView.frame.size.height * 0.5, _tableView.frame.size.width, _tableView.frame.size.height * 0.5)];

        bk1.backgroundColor =[UIColor whiteColor];

        [tableBackgroundView addSubview:bk1];

        _tableView.backgroundView = tableBackgroundView;


©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容