UITableView Image

I am trying to set up a png image as the background of a table. The following code is okay! But only on the iPhone Simulator. If I try to run the application on the iPhone, the background of the tableview will remain white (or clear). What you do is what I was trying to set the background color about. I tried many ways until the next, but everyone has the same problem.

self.tableView.backgroundColor = [UIColor clearColor]; self.tableView.opaque = NO; self.tableView.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"TableViewBackground.png"]]; 

Thank you in advance!

+54
background-color iphone uitableview background
Apr 28 2018-11-21T00:
source share
11 answers

Please use the following code.

 UIImageView *tempImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"TableViewBackground.png"]]; [tempImageView setFrame:self.tableView.frame]; self.tableView.backgroundView = tempImageView; [tempImageView release]; 

Thank,

+164
Apr 29 '11 at 4:12
source share

I think this approach is cleaner:

 UIColor *background = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"TableBackground.jpg"]]; self.tableView.backgroundColor = background; [background release]; 
+17
Jan 03 2018-12-12T00:
source share

Is your image actually named TableViewBackground.PNG (pay attention to capitals)? You need the case to match exactly on the iOS device, while it does not need to exactly match the Simulator.

+7
Apr 29 '11 at 4:22
source share

Simple quick version will be

 let tempImageView = UIImageView(image: UIImage(named: "yourImage")) tempImageView.frame = self.tableView.frame self.tableView.backgroundView = tempImageView; 
+6
Feb 28 '16 at 13:39
source share
  UIImageView *tempImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"TableViewBackground.png"]]; [tempImageView setFrame:self.tableView.frame]; self.tableView.backgroundView = tempImageView; [tempImageView release]; 

This works great. Thanks to Jona Rabbi

+5
Mar 26 '13 at 11:38
source share

A subclass of IBDesignable tableview that allows you to attach an image from the interface constructor

 import UIKit @IBDesignable class DesignableTableView: UITableView { @IBInspectable var backgroundImage: UIImage? { didSet { if let image = backgroundImage { let backgroundImage = UIImageView(image: image) backgroundImage.contentMode = UIViewContentMode.ScaleToFill backgroundImage.clipsToBounds = false self.backgroundView = backgroundImage } } } } 
+3
Aug 25 '15 at 23:05
source share
 [TableView setBackgroundView:nil]; [TableView setBackgroundView:[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"apple.png"]] ]; 
+2
Aug 12 '14 at 12:59 on
source share

This works great, also if you want to use an image for your background.

 UIImage *image = [UIImage imageNamed:@"something.png"]; self.tableView.backgroundView = nil; self.view.backgroundColor = [UIColor colorWithPatternImage:image]; 
+1
Jun 22 '13 at 23:50
source share

A bit late, but maybe for everyone else looking for a solution. I could get this working using the following code in the viewDidLoad method of the UITableViewController :

 self.parentViewController.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"background.png"]]; self.tableView.backgroundColor = [UIColor clearColor]; 

or using only the background color:

 self.parentViewController.view.backgroundColor = [UIColor scrollViewTexturedBackgroundColor]; self.tableView.backgroundColor = [UIColor clearColor]; 

It took me a while to figure this out, but now it works like a charm.

0
Aug 12 '13 at 17:50
source share

Objective-c version:

 cell.backgroundColor = [UIColor clearColor]; 

Also see this: How to create a UITableViewCell with a transparent background

0
Dec 21 '16 at 9:32
source share
 UIImageView *imageviewTemp = [[UIImageView alloc] init]; [(UIImageView *)imageviewTemp sd_setImageWithURL:[NSURL URLWithString:self.stringOfPassedImage]]; [imageviewTemp setFrame:self.tableView.frame]; self.tableView.backgroundView = imageviewTemp; 
-3
Aug 04 '16 at 7:23
source share



All Articles