We help IT Professionals succeed at work.

How to put gradient style table cell in a table?

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

Do more with

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

Commented:
I would highly suggest using an image but here is a possible solution.
http://slayeroffice.com/code/gradient/

Commented:
You can draw whatever you want in the drawRect method.
Mac OS X Reference Library. Advanced Drawing Techniques
http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/CocoaDrawingGuide/AdvancedDrawing/AdvancedDrawing.html

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:
http://en.wikibooks.org/wiki/Programming_Mac_OS_X_with_Cocoa_for_beginners/Graphics_-_Drawing_with_Quartz

I did find the gradient for iPhone SDK here:
http://stackoverflow.com/questions/422066/gradients-on-uiview-and-uilabels-on-iphone
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:
Gradients
http://developer.apple.com/iphone/library/documentation/GraphicsImaging/Conceptual/drawingwithquartz2d/dq_shadings/dq_shadings.html#//apple_ref/doc/uid/TP30001066-CH207-TPXREF101

 
Commented:
http://www.cimgf.com/2010/01/28/fun-with-uibuttons-and-core-animation-layers/
has a very good example using gradients.
you can treat uibuttons as uitableviewcells.