到目前为止,为了在录制时突出显示我的单元格的错觉,它只是实现了tableView:didSelectRowAtIndexPath:
这样:
tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
tableView.deselectRowAtIndexPath(indexPath, animated: false)
}
现在我通过覆盖drawRect
来自定义我的单元格的contentView(实际上是contentView的子视图)的渲染。问题是我的伎俩不再“耍手段”了。
所以我考虑像这样实施tableView:didHighlightRowAtIndexPath:
和tableView:didUnhighlightRowAtIndexPath:
:
override func drawRect(rect: CGRect) {
let context: CGContextRef = UIGraphicsGetCurrentContext()
let colors: [CGColor]!
if isHighlighted {
colors = [UIColor.blackColor().CGColor, UIColor(red: 230/255, green: 230/255, blue: 230/255, alpha: 1).CGColor]
} else {
colors = [UIColor.whiteColor().CGColor, UIColor(red: 230/255, green: 230/255, blue: 230/255, alpha: 1).CGColor]
}
let rect = self.bounds
GraphicHelper.drawLinearGradient(context, rect: rect, colors: colors)
let strokeRect = CGRectInset(rect, 1, 1)
CGContextSetStrokeColorWithColor(context, UIColor.whiteColor().CGColor)
CGContextSetLineWidth(context, 1)
CGContextStrokeRect(context, strokeRect)
let separatorColor = UIColor(red: 208/255, green: 208/255, blue: 208/255, alpha: 1).CGColor
let startPoint = CGPointMake(rect.origin.x, rect.origin.y + rect.size.height - 1)
let endPoint = CGPointMake(rect.origin.x + rect.size.width - 1, rect.origin.y + rect.size.height - 1)
GraphicHelper.drawStroke(context, startPoint: startPoint, endPoint: endPoint, color: separatorColor, width: 1)
}
它可以解决这个问题,但仅限于“长”水龙头,因为它不起作用或短暂的水龙头是完全没用的。
关于如何实现这一目标的任何建议?
答案 0 :(得分:0)
我的愚蠢想法
将UIImageView
放入自定义单元格内容视图中以用于后台目的。 (设置白色或透明图像)
在didSelectRowAtIndexPath
中更改UIImageView
的图片并重置上次选择的单元格图片。
你也可以改变背景颜色。