将UIView背景色设置为UITableViewSelectionStyle默认

时间:2018-11-18 21:05:21

标签: swift

我创建了不在UITableView或UITableViewCell中的UIView。我希望能够在视图的touchesBegan函数中突出显示该视图,并且此UIView的backgroundColor与此单元格的颜色相同。下面是我正在使用的代码。不幸的是,.lightgray看起来与selectionStyle = .default所使用的颜色不同。还有另一种方法可以将该视图设置为与UITableViewCells相同的颜色吗?

override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
    self.backgroundView.backgroundColor = .lightGray
    super.touchesBegan(touches, with: event)
}

0 个答案:

没有答案