Ios 长按单元格时,TableView单元格背景色未更改
我已将表格视图单元格选择背景颜色更改如下Ios 长按单元格时,TableView单元格背景色未更改,ios,swift,cell,Ios,Swift,Cell,我已将表格视图单元格选择背景颜色更改如下 var cell = tableView.cellForRowAtIndexPath(indexPath) let selectionColor = UIView() as UIView selectionColor.layer.borderWidth = 1 selectionColor.layer.borderColor = utility.uicolorFromHex(0xEBEBEB).CGCol
var cell = tableView.cellForRowAtIndexPath(indexPath)
let selectionColor = UIView() as UIView
selectionColor.layer.borderWidth = 1
selectionColor.layer.borderColor = utility.uicolorFromHex(0xEBEBEB).CGColor
selectionColor.backgroundColor = utility.uicolorFromHex(0xEBEBEB)
cell!.selectedBackgroundView = selectionColor
它会改变背景色,但当我长按单元格时,背景色仍与默认值相同(深灰色)。我想更改按和长按单元格选择的背景色。如何做到这一点?您必须禁用选择样式(因为选择样式包含默认的灰色) 之后,再加上长按手势和动作。执行所需的编码
let longpress = UILongPressGestureRecognizer(target: self, action: "longPressGestureRecognized:")
tableView.addGestureRecognizer(longpress)
现在,使用以下代码添加longPressGestureRecognited
功能:
抄袭
在longpressurerecognized()
函数中,首先获取手势在表格视图中的位置以及相应的tableViewCell
在longpressurerecognized()函数中添加以下代码:
抄袭
希望有帮助。u可以在单元格中添加长按手势,并设置单元格bg颜色。您是何时执行这些代码的?谢谢llesh…它使用长按手势工作。。
let longpress = UILongPressGestureRecognizer(target: self, action: "longPressGestureRecognized:")
tableView.addGestureRecognizer(longpress)
func longPressGestureRecognized(gestureRecognizer: UIGestureRecognizer) {
}
let longPress = gestureRecognizer as UILongPressGestureRecognizer
let state = longPress.state
var locationInView = longPress.locationInView(tableView)
var indexPath = tableView.indexPathForRowAtPoint(locationInView)