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.

Answers


add this line in you code where you want to set background color for your image

[YourView(or imageView) setbackgroundColor:[UIColor groupTableViewBackgroundColor]];

Thanks


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];

or:

// 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


Need Your Help

Is there any function in vb.net as an alternative to magic methods __get() and __set() in php

vb.net get encapsulation getter

PHP has magic methods like __get() and __set(). Is there any alternative for it in vb.net. Or is there any other tricks that can be done instead?

Google Analytics Custom Parameter Name

google-analytics analytics

I want to track if page views come from navbar, header, footer, etc. The Google Analytics parameters are long and annoying. Does Google Analytics support custom GET parameter names?

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.