iOS开发

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

2019-12-20  本文已影响0人  神奇李白

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

更改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;

上一篇 下一篇

猜你喜欢

热点阅读