views:

43

answers:

1

I have a standard, grouped UITableView that I am trying to add a custom background to (instead of the boring gray stripes). Ultimately, my designer would like the table view to "slide over" or "float over" the background. I have gotten as far as setting the background of the table view to "clear" with the hopes of showing a static image underneath.

How can I modify my current classes and view controllers to achieve this?

+1  A: 

You need to do one of two things.

1) Add an image view under the table view. You can do this like this:

[tableview.superview insertSubview:imageView belowSubview:tableview];

The caveat here is that sometimes you'd rather not manipulate the view stack in code.

2) You can draw the background yourself in a UITableView subclass. If you do this, make sure you're setting the tableview's bg color to clear first. Here's my class:

@interface ATSImageTableView : UITableView {
    UIImage *backgroundImage;
}

@property (nonatomic, retain) IBOutlet UIImage *backgroundImage;

@end

and:

@implementation ATSImageTableView

@synthesize backgroundImage;

- (void)drawRect:(CGRect)rect {
    [backgroundImage drawAtPoint:CGPointZero];

    [super drawRect:rect];
}

- (void)dealloc {
    [backgroundImage release];
    [super dealloc];
}

@end

Hope this helps!

Ben Lachman