【问题标题】:change the color of the tableView?.tableFooterView改变 tableView?.tableFooterView 的颜色
【发布时间】:2017-02-03 15:41:29
【问题描述】:

我创建了一个如图所示的 tableView。部分和单元格之间有空间。所以空间的颜色就是tableview默认颜色。

为了删除 tableview 上的多余行,我添加了一个 UIVIew() 到 tableView?.tableFooterView

let footerView = UIView()
self.tableView?.tableFooterView = footerView

我想让 UIView 的颜色在图片上的“目标颜色”中相同。

我尝试了下面的方法,但它不起作用。

let footerView = UIView()
footerView.backgroundColor = UIColor.black
footerView.tintColor = UIColor.black
self.tableView?.tableFooterView = footerView

我该怎么办? 谢谢!

【问题讨论】:

  • 由于您没有设置页脚视图的高度,并且这不是要走的路,所以在 nirva D 已经提到的表格背景视图上设置您想要的颜色

标签: ios uitableview swift3


【解决方案1】:

尝试为此设置tableViewbackgroundColor

self.tableView?.backgroundColor = UIColor.white //Or color that you want

【讨论】:

    【解决方案2】:

    如果您想为 tableview 页脚使用不同的颜色,还有另一种解决方案。

    斯威夫特 4

        tableView.tableFooterView = UIView()
        let screenRect = view.bounds;
        let screenWidth = screenRect.size.width;
        let screenHeight = screenRect.size.height;
        let footerHeight = screenHeight - ((YOUR_SECTION_HEIGHT * SECTION_COUNT) + (YOUR_ROW_HEIGHT * ROW_COUNT))
        let footerView = UIView(frame: CGRect(x: 0.0, y: 0.0, width: screenWidth, height: screenHeight - footerHeight))
        footerView.backgroundColor = UIColor.darkGray // or your custom color
        tableView.tableFooterView?.addSubview(footerView)
    

    Objective-C

        self.tableView.tableFooterView = [[UIView alloc] init];
        CGRect screenRect = self.view.bounds;
        CGFloat screenWidth = screenRect.size.width;
        CGFloat screenHeight = screenRect.size.height;
        CGFloat footerHeight = screenHeight - ((YOUR_SECTION_HEIGHT * SECTION_COUNT) + (YOUR_ROW_HEIGHT * ROW_COUNT));
        UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, screenWidth, screenHeight - footerHeight)];
        footerView.backgroundColor = [UIColor darkGrayColor]; // or your custom color
        [self.tableView.tableFooterView addSubview:footerView];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-12
      • 2015-12-31
      • 2015-06-04
      • 1970-01-01
      相关资源
      最近更新 更多