In order to create a custom background for a transparent
UITableView you’ll need to do a few things. I’ve got the basic code below after a lot of tinkering. I’ve also included how to make it so you can hide the
UITableView when you tap in the transparent areas below the rows using a
UITapGestureRecognizer. In the images below you can see the custom view in action.
- Don’t subclass
UITableView, instead use it as a instance variable in your own custom UIViewController subclass.
- Create a custom
UIViewsubclass to use as the background view, this will be visible when the
UITableViewis hidden or has a transparent background view.
- On iPad make sure you clear the UITableView’s
backgroundViewand set it to
nilin addition to setting the background color to
- Register a
UITapGestureRecognizerwith the viewController’s view and then set the attribute
NOso that the touches from the gesture propagate to both the
UITableViewand the custom background view.
- In the
-(void)handleTapGesture:method you’ll want to send taps that don’t touch a row to toggle the UI so that the
UITableViewhides or unhides.
- I show a
UINavigationBar, so my
UITableViewframe needs to take into account the size of the navigation bar.
- Set the UILabel’s or custom views backgroundColor in the table’s cells to have
[UIColor clearColor]so that they animate and fade correctly.
See the sample code below:
- No public Twitter messages.
TagsApple application testing App Store Artwork Evolution Boost bundle C++ cross platform development Dual Monitors Facebook Gears of War 2 gestures git GLUT iOS iPad iPhone iphone dev iphone dev 101 logic testing Mac Macbook Pro mac osx Mac OS X NSDocument Objective-C OCUnit OpenGL player/stage presentation remote control resource paths RIT SCM skillshare slides tdd testable code testing unit testing Windows XP Xbox 360 Xcode xcode 4