I have done a fair bit of googling on this and I can't find the right solution. I have a UITableView of which I want to change the colour of the background of the cells. I have found solutions to doing this but it only deals with cells which have content or data as it were.
I need to colour the background of those unused cells as well.
Try setting the background colour of the tableView itself. Those "empty cells" at the bottom aren't really cells at all - they're just separator lines drawn over the background.
Even though UITableViewCell inherits from UIView, changing the backgroundColor property of the cell itself won't do anything. You need to change the background color of the cell's contentView, such as
cell.contentView.backgroundColor = [UIColor greenColor];
This is because the subviews of a UITableViewCell are actually subviews of the cell's contentView, because the contentView knows how to resize its subviews if a cell is put into editing mode; the cell itself doesn't know how to do that.
I'm not sure what you mean by unused cells. If you tell your tableView there are 10 cells and you only provide content for 8 of them, you'll still have 10 green cells, if that's what you mean by "unused".
Is it possible to set the background color of a section of a UITableView.
I want to set the background color of one section to "UIColor clearColor".
When I did, its showing the transparent section with border. How can I prevent the border.
You need to set separatorStyle property of your UITableView to UITableViewCellSeparatorStyleNone and draw borders inside your cells. Add and position 1px UIView and hide it when you don't need the border to be shown.
I had a UITableView that I replaced with a UIPopoverController. My UITableView's background was set to clearColor and it showed the custom background through the table. The table cells also matched the grey tint of my background image.
Now when I use the UIPopovercontroller, with the background set to clearColor, I can see through my UIPopoverController, but the color is the "standard" popover controller color. The kind of grey/blue tint. Is there a way to change that? Thanks.
I have a problem where my UITableView (group style) has a black "tip" above it's rounded corner.
I'm setting up the background of the tableview like so:
[meetingTableView setBackgroundColor:[[UIColor alloc] initWithPatternImage:[[UIImage alloc] initWithContentsOfFile:#"background.png"]]];
And my table view ends up looking like this:
black pointy edge on rounded corner http://papernapkin.org/pastebin/resource/images/imageEntryId/6487
Any ideas how I can get rid of those black points?
I have got the same problem.
When I set clear color by xib, I have the back corner
The solution is to set it by code !
(The same problem with interface builder exist for webviews)
Try this in your controller's viewDidLoad method:
meetingTableView.backgroundColor = [UIColor clearColor];
You'll get Black corners on UITableView Group Style if you set background color to clear color in XIB.
Instead try this code for removing Black corners on UITableView Group Style
tableViewObject.backgroundColor=[UIColor clearColor];
Just in case you weren't already aware, there's another neat technique you can use to make customized backgrounds for UITableViews:
Not quite as simple as setting the background as you're doing, but it gives you a lot more flexibility and can scale to any table size.
Maybe if you put yourTableViewOutlet.backgroundView=nil;
To avoid the black corners you have to make sure that the UITableViewCells are not opaque. It looks like you're using custom styles table cells and the default value for opaque is YES. Either go to Interface Builder and uncheck the opaque checkbox if the table cell was set up in a XIB file. Or use the setOpaque:NO setter to change value.
Because the table cell view still has a rectangular frame even with the rounded corners the cell view and not the actual table view is causing those black corners.
My guess is that it's related to something that you're doing in your custom table view cells. You might want to experiment with setting the cell background color to [UIColor clearColor].
I think you should set the background color of your table as clearColor and initialsie your view with the background image.
Then it will definitely not show the black corners. But also don't forget to set the background color of your cell as white color
The up-voted answer above (set the tableView's background to [UIColor clearColor]) may not work for you if you are like me and never use the UITableViewController, instead putting a UITableView inside a UIViewController.
In this case it's not the tableView that needs to have a clear background, but the view that holds the tableview.
This is not intuitive, but it works for me. In interface builder you can just set the parent view's background color to clear color, or you could do the same in code in viewDidLoad with:
self.view.backgroundColor = [UIColor clearColor];
I'm guessing the reason for the black corners is something about the internal graphics optimization, and setting the background clear fixes it.
I've read (and used) the code here which illustrates how to change the background color and border color of a UITableViewCell in grouped mode on the iPhone. I'm writing an app now which has a non-grouped UITableView and I need to change the border color of the cells. I know that I can modify the code and create a new background view and apply it, but is it necessary?
Is there an easy way to specify the border color of a UITableViewCell if it is a non-grouped style?
If by "border color" in a plain table view you mean the separator lines between the cells (default color gray), you can customize this color for the whole table view via:
tableView.separatorColor = [UIColor blueColor];
See the UITableView reference.