I have a custom UITableViewCell. All the drawing is done in the drawRect: method and no subviews are added. The drawing works fine and the scroll speed is good. But the problem is with the selected cells. I want the selection to behave like it would normally:
- Blue gradient selection color
- Inverted text color
- Animated deselection
我没能做到这三点。
First attempt:
Set selectionStyle = UITableViewCellSelectionStyleNone and do the selection color in the drawRect method.
With this method, I am able to achieve the first two things, but the deselection is instant. So one second it is selected blue, the next second it is deselected. I do not get the nice fade-out.
Second attempt:
selectionStyle = UITableViewCellSelectionStyleBlue
With this method my cell is all gradient blue when selected. The text I have is not visible. The fade-out works nicely, though.
Third attempt:
Set selectionStyle = UITableViewCellSelectionStyleBlue and also set selectedBackgroundView to a UIView where I set the backgroundColor to a transparent blue.
Here the problem is that the selectedBackgroundView (despite the name) is drawn on top of my normal content. So if the selectedBackgroundView is not transparent, I cannot see the text. And if it is transparent, I can see the text, but the selection color gets "faded" and does not look right.
实现这三个要点的正确方法是什么