adding background image to uitable causes tiling on table cells

Discussion in 'iOS Programming' started by johnmerlino, Dec 7, 2011.

  1. johnmerlino macrumors member

    Oct 22, 2011
    Hey all,

    When my table view loads, on the viewDidLoad I add this line of code:

                  self.tableView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"unit_list_bg.png"]];
    That line of code correctly displays the image on the table view but it also tiles the image on each of the cells, which is not what I want, as shown on the image attached to this post.

    I just want the background image to be the background of the table not each table cell.

    Also note that I originally had the background image applied to the view but the problem with that is the blue navigation bar on top clipped part of the image:

                self.parentViewController.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"unit_list_bg.png"]];
                self.tableView.backgroundColor = [UIColor clearColor];
    thanks for response

    Attached Files:

  2. jnoxx macrumors 65816


    Dec 29, 2010
    Aartselaar // Antwerp // Belgium
    You are using a UIColor attribute for images. I know that it's possible.. but just, why? :p
    I think you don't really understand the layers yet in an iOS frontend.
    And to get a background on the tableview, just set it on the view behind the tableview, and make the tableview.backgroundcolor -> UIColor clearColor.
    Since we don't even know what you are exactly trying to achieve, I cant give tips actually >;<
  3. PhoneyDeveloper macrumors 68040


    Sep 2, 2008
  4. johnmerlino, Dec 8, 2011
    Last edited: Dec 8, 2011

    johnmerlino thread starter macrumors member

    Oct 22, 2011
    On the original question, I mentioned I tried that. But the blue navigation bar on the top eclipses it.

    I kind of resolved this like this:

    self.tableView.backgroundView = [[UIImageView alloc] initWithImage:[[ UIImage imageNamed:mad:"bg.png"] stretchableImageWithLeftCapWidth:20 topCapHeight:0]];

Share This Page