How to set UITableView background to image?
I've noticed that a number of apps have a custom background image for UITableView (or have set the background to a color.)
I can't find any API in the UITableView class to affect this, and my attempts in interface builder have failed (trying to set the color of the UIView)
Any suggestions? I've seen a third party app with pictures, so I know it can be done.
add this line in you code where you want to set background color for your image
[YourView(or imageView) setbackgroundColor:[UIColor groupTableViewBackgroundColor]];
I just ran into the same question myself, but I found a way to do it that TomSwift touched on. As he mentioned, UITableView has a backgroundView property that is intended to do just what you're looking for. If you want to set the background color, you should instead use the backgroundColor property, as others have said. So:
// Set an image as the background of a UITableView called 'tableView' UIImageView *bg = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"MyImage.png"]]; [tableView setBackgroundView:bg];
// Set a solid color as the background of a UITableView called 'tableView' // In this case I chose red [tableView setBackgroundColor:[UIColor redColor]];
UIImageView *image = [[UIImageView alloc] initWithImage: [UIImage imagenamed:@"no_image.png"]]; [self.view addSubview:image]; UITableView *tableview = [[UITableView alloc] init]; [image addSubview:tableview]; tableview.backgroundcolor = [UIColor clearColor];
try this. it works for me.
CALayer *background = [CALayer layer]; background.zPosition = -1; background.frame = self.view.frame; background.contents = [[UIImage imageNamed:@"background.jpg"] CGImage]; [tableView.layer addSublayer:background];
you need to add an image view and set the table background color to clear color see this link for tutorial