views:

53

answers:

1

Hey, I am making a custom table cell right now but my custom cell is just white cell with some buttons and labels in background color which looks not that great. Is there a way to render the background color so that the cell has some vertical gradient effect? For example, on top of the cell it looks white and as it gets closer to center of the cell, it gets darker. But as it gets closer to the bottom of the cell, it gets whiter again.

A great example would be this free app called "friendsaroundme". Another thing is that I don't want to use custom image to do it (i.e make the cell.backgroundcolor = [uicolor colorwithpatternimage:somethingsomething.png..... ) because it's not that flexible. So is there anyway to render the gradient style programatically?

+1  A: 

You can use a CAGradientLayer as the background layer. Remember a table view cell is just a UIView. You can add a new layer to the layer tree with:

[[[self view] layer] addSublayer:gradientLayer];

I wrote a blog post on how to do this with UIButtons. The same technique applies.

Matt Long
thanks matt! your example was like super super helpful!
David Gao