We help IT Professionals succeed at work.

How to put gradient style table cell in a table?

privateson used Ask the Experts™
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?
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

I would highly suggest using an image but here is a possible solution.

You can draw whatever you want in the drawRect method.
Mac OS X Reference Library. Advanced Drawing Techniques

Pay attention on NSGradient and the example for it in this link.

Sorry, only now I see that the question can be about iPhone SDK. I do not know if NSGradient is there. But drawRect works always. :) For a test, for a beginning, you can try these examples from here:

I did find the gradient for iPhone SDK here:
The last code in that thread contains the code you need for iPhone - manually created gradient fill for the rectangle.

And here is iPhone OS Reference Library with full explanation and many samples:

has a very good example using gradients.
you can treat uibuttons as uitableviewcells.