Set image as background for TableView with storyboard in iOS

The storyboard causes me a lot of problems !: (

Now I'm trying to put the image as the background of the table in iOS. I made a PNG image with transparency in Photoshop, and I imported it into my project.

** First question: is it possible to set the background of the image in the storyboard? I thought it was a good idea to create and view the image and put it in my table view ... but the storyboard does not allow me to do this.

** I also tried adding a background image using code:

- (void)viewDidLoad { [super viewDidLoad]; self.tableView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"table_background.png"]]; ... } 

I got a terrible result with a black background instead of white, even if png is transparent!

In addition, I read that to optimize performance, it is better to avoid transparent background for the cells.

So, what is the best way to set an image as a background to represent a table with a storyboard?

Thanks in advance, Yas

+6
source share
1 answer

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

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

Then add a UIImageView (but only for 3.2+)

Avoid using backgroundColor for this kind of thing ^^

Using only the story panel, I do not know: -] but it should work with this method.

Btw check that your tableView and cell have a clear backgroundColor, there might be a problem.

Good luck.

+2
source

Source: https://habr.com/ru/post/902482/


All Articles