Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set an image as background for TableView with Storyboard in iOS

Storyboard is causing to me a lot of problems! :(

Now I'm trying to put an image as a background of a tableview in iOS. I've done a png image with transparency in photoshop and I've imported it into my project.

** The first question is: is it possible to set the image background in storyboard? I thought that a good idea was to create and image view and put it on my table view... but storyboard doesn't allow my to do this.

** I've also tried to add the background image via code:

- (void)viewDidLoad
{
[super viewDidLoad];

self.tableView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"table_background.png"]];

...
}

I obtained an horrible result with a black background instead of white, even if the png is transparent!

Moreover I've read that to optimize performances, it should be better to avoid transparent background for cells.

So, what it the best way to set an image as a background for a table view with storyboard?

Thank you in advance, yassa

like image 950
yassassin Avatar asked Nov 27 '11 10:11

yassassin


1 Answers

I think you have a method to set a background view for a tableView

[ tableView setBackgroundView:<#(UIView *)#> ];

And then add an UIImageView (but only for 3.2+)

Avoid using backgroundColor for this kind of things ^^

Using only story board I don't know :-] but with this method it should work.

Btw check that your tableView & cell have a clear backgroundColor, may be the problem too.

Good luck.

like image 151
Vinzius Avatar answered Nov 14 '22 22:11

Vinzius