我已经更改了表视图单元格选择背景颜色,如下所示.
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
它会改变背景颜色,但是当我长按单元格时,背景颜色保持默认(深灰色).我想改变印刷机和长按单元格选择背景颜色.怎么做 ?
解决方法
您必须禁用选择样式(因为选择样式包含默认的灰色)
cell.selectionStyle = .None
之后添加长按手势和动作.做所需的编码.
let longpress = UILongPressGestureRecognizer(target: self,action: "longPressGestureRecognized:") tableView.addGestureRecognizer(longpress)
现在,使用以下代码添加longPressGestureRecognized函数:
复制
func longPressGestureRecognized(gestureRecognizer: UIGestureRecognizer) { }
在longPressGestureRecognized()函数内部,首先在表视图中获取手势的位置以及相应的tableViewCell.
在longPressGestureRecognized()函数中添加以下代码:
复制
let longPress = gestureRecognizer as UILongPressGestureRecognizer let state = longPress.state var locationInView = longPress.locationInView(tableView) var indexPath = tableView.indexPathForRowAtPoint(locationInView)
希望能帮助到你.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。