UITableView background Image

前端 未结 12 1881
情歌与酒
情歌与酒 2021-01-29 21:21

I\'am trying to setup a png image as my tableview\'s background. With the following code all are fine! But only on iPhone Simulator. If I try to run the application on an iPhone

相关标签:
12条回答
  • 2021-01-29 21:58

    Is your image actually named TableViewBackground.PNG (note the capitals)? You need to have the case match exactly on an iOS device, whereas it doesn't need to match exactly in the Simulator.

    0 讨论(0)
  • 2021-01-29 22:02

    Objective-c version:

    cell.backgroundColor = [UIColor clearColor];
    

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

    0 讨论(0)
  • 2021-01-29 22:04
     UIImageView *tempImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"TableViewBackground.png"]];
    [tempImageView setFrame:self.tableView.frame]; 
    
    self.tableView.backgroundView = tempImageView;
     [tempImageView release];
    

    This works perfect. Thanks to Ravin by Jona

    0 讨论(0)
  • 2021-01-29 22:04

    An IBDesignable tableview subclass that will let you attach an image from interface builder

    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
                }
            }
        }
    
    }
    
    0 讨论(0)
  • 2021-01-29 22:05

    This works perfectly fine, also if you want to use a pattern image for your background.

    UIImage *image = [UIImage imageNamed:@"something.png"];
    self.tableView.backgroundView = nil;
    self.view.backgroundColor = [UIColor colorWithPatternImage:image];
    
    0 讨论(0)
  • 2021-01-29 22:06
    UIImageView *imageviewTemp = [[UIImageView alloc] init];
    [(UIImageView *)imageviewTemp sd_setImageWithURL:[NSURL URLWithString:self.stringOfPassedImage]];
    [imageviewTemp setFrame:self.tableView.frame];
    self.tableView.backgroundView = imageviewTemp;
    
    0 讨论(0)
提交回复
热议问题