I want to set an image as the background for my uitableview
. This is the code I am using:
self.tableView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"background_tableview.png"]];
This is showing the image right but as soon as the table is populated something weird happens. Parts of images are shown in each tableviewcell
and also the image scrolls along with the table. How can I make it so that the image remains fixed and that each tableviewcell
doesn't show part of the image?
Thanks,
TC
You don't want to set the background of the UITableView
if you don't want it to scroll. Instead, you want to set the background of the UITableView
to be transparent - and provide your own fixed background behind the UITableView
.
To do this, first set the background of the UITableView to "Clear Color".
Programmatically: self.tableView.backgroundColor = [UIColor clearColor];
You'll also want to un-check the opaque checkbox.
Programmatically: self.tableView.opaque = NO;
Setup the fixed background you want in the view behind the UITableView
.
Make sure any sub-views in any of your UITableViewCell
s are also backgroundColor = [UIColor clearColor];
(UITextView
s, etc.)
Image for the TableView background
self.tableView.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"your_image"]];
Do not forget write the file name with the image's type. EXAMPLE:
self.tableView.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"myPhoto.png"]];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With