Selected state for custom UITableViewCell using drawrect (with animation)

I'm trying to figure out the best way to use drawRect for something like the cell in the image below and still animating between the selected and unselected states:

Custom UITableViewCell

I've seen a few suggestions with the most advanced, it would seem, the this one's:

But that still seems pretty hacky, so I'm not quite for sale. It feels like there should be a cleaner path.

I suppose the other option could have two different UIViews, one showing the unselected state, and the one that drew the selected state (the latter is probably a subclass of the former with slightly different direct output). Then can you add both of them to the contentView and hide / disappear in between? It won't support editing mode or accessories very well, but maybe that's okay?

Or maybe you are following the same method but inserting them into backgroundView and selectedBackgroundView respectively?

Or, if someone respects this cell structure, perhaps you are really only drawing the background (the title I am assuming in the image above), in the backgroundView, darkening on the selected BackgroundView, and painting everything else in the uiview subclass added to the contentView? But then you are drawing a couple of different places (creating your own contexts as I imagined) and there will still be problems with text / decorative images not animating by accepting these changed colors.

So what's the answer?

+3


source to share





All Articles