UITableView Transparent - cocoa-touch

I just want to know how i can set a transparent background of an UITableView.
I got this :
tableview.backgroundcolor = [UIColor clearColor];
But the cells stay white and not transparent.
Thank for help
Flo.

That statement is correct for setting the tableView's background color to clear (transparent), not the cells.
You have to manipulate cells directly, as they themselves are views. When you set the background color of a table cell however, you are not setting the background color of its content view. So unless you do that specifically, you won't see through the cell. Try this to make transparent the cell background and the cell's contentView background:
cell.backgroundColor = [UIColor clearColor];
cell.contentView.backgroundColor = [UIColor clearColor];
(Written from memory here, not compiled... :-)

Related

Change UITableViewCell background color without animation

Changing of cell background color have some weird animation. I want to change this color immediately without animation. Maybe I should override setBackgroundColor method in subclass somehow?
cell.backgroundColor = [UIColor redColor];
Probably that you are changing that color while a UIView animation is in progress (a transition, a tableView row update, a UIView animation block, etc).
Try the following:
[UIView performWithoutAnimation:^{
cell.backgroundColor = [UIColor redColor];
}];
UPDATE: I'm not sure what kind of animation you got though. I made a simple test UITableViewController that change the cell color without animation when you tap on them (using what you specified in your comment), and it works.

changing the background color of each other cell in objective C

I have a uiTableView. I want that each other cell gets another background color. I am trying it like this. But it won't work. Anybody have a clue?
if(indexPath.row % 2 == 0){
cell.backgroundColor = [UIColor whiteColor];
}else{
cell.backgroundColor = [UIColor blueColor];
}
Kind regards,
Stef
You can use : cell.contentView.backgroundColor instead of cell.backgroundColor inside tableView:cellForRowAtIndexPath:
Or : (from Apple docs)
Note: If you want to change the background color of a cell (by setting
the background color of a cell via the backgroundColor property
declared by UIView) you must do it in the
tableView:willDisplayCell:forRowAtIndexPath: method of the delegate
and not in tableView:cellForRowAtIndexPath: of the data source.
Changes to the background colors of cells in a group-style table view
has an effect in iOS 3.0 that is different than previous versions of
the operating system. It now affects the area inside the rounded
rectangle instead of the area outside of it.
cell.backgroundView=[[UIView alloc]initWithFrame:cell.frame];
[cell.backgroundView setBackgroundColor:[UIColor blueColor]];
will do the job or
[cell.contentView setBackgroundColor:[UIColor blueColor]];
To answer the expanded question in the comments, set the background colour of your labels to label.backgroundColor = [UIColor clearColor];

Change background color of Reorder icon in UITableView

In my UITableView: My cell is yellow, but the re-order icon is white :(
Any quick fix for this? Preferably without having to subclass UITableView or hacking to much.
BTW, this desperate attempt has no effect:
cell.backgroundColor =
cell.backgroundView.backgroundColor =
cell.contentView.backgroundColor = [UIColor myNiceYellowColor];
Thanks!
Don't use - cell.contentView.backgroundColor = [UIColor myNiceYellowColor]; instead change the complete cell color in datasource method -tableView:willDisplayCell: forRowAtIndexPath:.

Need Help Setting UITableViewCell's Background Image

I'm using a background image for my UITableViewCell.
If I just set the background of the cell, but keep everything else the same, I get this:
I'm if I use this code in viewDidLoad and it fixes the cell but it is making the navbar transparent:
self.navigationController.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"background.png"]];
self.tableView.backgroundColor = [UIColor clearColor];
Is there way to get the navbar back and get the cell looking normal?
For the most part, I don't believe UIPopovers have many visual options as far as background.

Background image for list view still shows white behind text for cells

I wanted to put a background image partially visible behind a list view. I created a list view in my nib with an image view behind it and made the list view background 20% opacity. This allows the background image to show thru but my text in the cells show a white background behind and if I create the cells in cellForRowAtIndexPath the cells have a white background too.
I am creating and setting the cell textLabel and the detailTextLabel in the cellForRowAtIndexPath event.
Not sure how to get rid of that, or if there is a better way to do the background image.
I had a similar issue and resolved it by setting the cell.contentView.backgroundColor to [UIColor clearColor] in cellForRowAtIndexPath.
If you did not want to make the whole cell transparent but the labels only, you can set the backgroundColor attribute of the textLabel and detailTextLabel to clear as well:
cell.textLabel.backgroundColor = [UIColor clearColor];
To set the background image of a table at run time rather than in a nib you can create a new UIColor from an image. Like so:
UIImage *img = [UIImage imageWithContentsOfFile: someFilePath]; // get your background image
UIColor *backgroundColor = [[UIColor alloc] initWithPatternImage: img];
[myTable setBackgroundColor: backgroundColor];
[backgroundColor release];