views:

631

answers:

3

I have a UITableView with a custom background image set like this:

self.tableView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"mybg.png"]];

The background appears fine, but my UITableViewCells (default cells, not custom) have some sort of weird tint to them, and the UILabel containing the "New Project" text also seems to have some sort of background behind it. How can I remove this? I've already tried:

cell.backgroundColor = [UIColor clearColor];
cell.textLabel.backgroundColor = [UIColor clearColor];

Thanks

alt text

A: 

Some times when your working with setting images for an app, and testing on the simulator, they get frozen to the app for the few run. Not sure, this is the case even if you delete the image files; they still keep popping up.

I would make that you have rest the simulator, and restart Xcode. Then force a rebuild of the app back on the simulator. This should clear out any images- even background images if they are still being referenced.

If this is not a solution that works...try making sure that you don't have conflicting commands going to the same UiTablView object-(1 from IB and 1 from Xcode programmically). Sometimes you can overlook that you have set something in IB, and it conflicts with what your telling it to do programically.

If that doesn't solve the issue...check the connections in IB and make sure your reffrencing the correct IBOutlet UITableView *tableview. And you have the delegat and data protocols in the header.

Newbyman
+1  A: 

I believe that this is a nasty side-effect of simply adding an image straight into your table view's backgroundColor.

Try adding the image to the view's background color:

[[self view] setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"mybg.png"]]];

and then set the table view's backgroundColor to be clear:

[[self tableView] setBackgroundColor:[UIColor clearColor]];

I hope this helps!

EddieCatflap
This did it, thanks!
macatomy
A: 

If you want to have each cell set with background and want to remove text's background, maybe you can try this...


- (void)viewDidLoad {
...
self.tableView.backgroundColor = [UIColor clearColor];
...
}

- (UITableViewCell *)tableView:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)indexPath {
...
cell.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"mybg.png"]];
cell.textLabel.backgroundColor = [UIColor clearColor];
...
}
Richard Chen