views:

656

answers:

2

I have a custom UITableViewCell with a custom layout. I wanted a gradient background, so in my UITableViewDelegate cellForRowAtIndexPath: method, I create a CAGradientLayer and add it to the cell's layer with insertSubLayer:atIndex: (using index 0). This works just fine except for two things:

Most importantly, I can't figure out how to change to a different gradient color when the row is highlighted. I have tried a couple things, but I'm just not familiar enough with the framework to get it working. Where would be the ideal place to put that code, inside the table delegate or the cell itself?

Also, there's a 1px white space in between each cell in the table. I have a background color on the main view, a background color on the table, and a background color on the cell. Is there some kind of padding or spacer by default in a UITableView?

+3  A: 

There's a really good article over on Cocoa with love about customising the look and feel of a table view. I think thank may answer your question.

Derek Clarkson
best link ever...MUCH appreciated. I'm really new to iPhone and porting an app from Android where I'm much more comfortable is proving to be pretty challenging.
Rich
Matt is awesome!
Michael
+2  A: 

I'm not sure about the first question but I think you can set the selectedBackgroundView property similarly to how you set the backgroundView property. The white space between cells is probably the separator. You can change that color like

tableView.separatorColor = [UIColor redColor];
Rob Lourens
I tried that, but maybe not the right way. Anyway, the link Derek provided above shows an example of setting tableView.separatorStyle to UITableViewCellSeparatorStyleNone which is probably what I'm looking for. Thanks for the response!
Rich