1

I've a grouped UITableView which has been resized and rounded. I would like to place a view BEHIND this table.I've tried:

[self.tableView addSubview:backgroundView];
[self.tableView sendSubviewToBack:backgroundView];

but it didn't work. This is what I obtain:

rounded uitableview

I would like to have the background in place of the black space.

Any idea?

Claus
  • 5,662
  • 10
  • 77
  • 118

2 Answers2

2

How about [self.tableView setBackgroundView:backgroundView];?

Phillip Mills
  • 30,888
  • 4
  • 42
  • 57
  • this place the image as background of the tableview (so limited in the area of the grouped table),instead I need a view BEHIND the table. – Claus Jul 26 '12 at 14:40
  • I'm not clear on the difference that you're describing. Do you mean something like `[self.tableView.superview addSubview:backgroundView]; ...;`? – Phillip Mills Jul 26 '12 at 15:05
  • yes,I'm trying that as well but it's not working. Getting really crazy. – Claus Jul 26 '12 at 15:19
  • At this point, I have no idea what it would need to look like for you to call it 'working'. :) – Phillip Mills Jul 26 '12 at 15:23
  • I've placed your code in viewWillAppear: and viewDidLoad but nothing :( – Claus Jul 26 '12 at 16:41
2

Bear with me I'm a beginner. I just ran into this problem and I found two solutions. In my case, I was using a UITableView object.

To begin, add the background image into your app's directory. I put mine in "Supporting Files"

You can add the image as a UIColor object:

    ...
    [resultsTable setBackGroundColor:setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"background.jpg"]]];
    ...

The problem with this method is that it will repeat your background image because it's treating it as a pattern.

The better way:

     // Create a string to store the path location of your image, otherwise you would have    to provide an exact path name
     NSString *backPath = [[NSBundle mainBundle] pathForResource:@"background"
     ofType:@"jpg"];

    // Create a UIImage Object to store the image.
     UIImage *bgImage = [[UIImage alloc ] initWithContentsOfFile:backPath];

     // Create a UIImageView which the TableView 
     UIImageView *bgView = [[UIImageView alloc]initWithImage:bgImage];

     // Set your TableView's background property, it takes a UIView Obj.
     [resultsTable setBackgroundView: bgView];
     .....
silverSuns
  • 218
  • 2
  • 16