views:

47

answers:

2

I'm trying to use a CAGradientLayer as a background for a UITableView. Everything works well until the overlaying view is scrolled, at which point then the pre-rendered background scrolls up and out of the way along with the original screen of data.

This is code that is being migrated from an iOS 3.1.3 app using a UIImage as a background to something device/resolution independent-looks great, works well, but sniffing the device type and using an alternate png isn't the sort of code that I want to ship, much less maintain.

Any suggestions as to how to do this?

A: 

You may have to make the table view transparent, and add the gradient layer to the table's superview. Keep in mind that your scrolling performance is probably going to be hideous—Core Animation will have to composite every subview of the table for every frame it displays. You may be able to slightly mitigate this by setting the cells' layers to rasterize themselves, as described here, but expect things to be pretty choppy regardless.

Noah Witherspoon
Thanks for taking a shot at it, I appreciate the help!
Mr. Pleasant
+1  A: 

Found the solution to what I was trying to solve, courtesy of Matt Gallagher:

http://cocoawithlove.com/2009/08/adding-shadow-effects-to-uitableview.html

His blog post has quite a few nice touches, including shadowing relevant cells instead of the whole table (mentioned as a performance issue in Noah's response).

Mr. Pleasant