Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a UITableViewCell with a transparent background

I'm trying to set the background color of a UITableViewCell to transparent. But nothing seems to work. I have some images/buttons inside the tableViewCell and I would like to make the white grouptableview background disappear to get a 'floating' effect for the images and buttons (as if they were not inside the tableview).

Any idea how this could be accomplished?

like image 731
levi Avatar asked Jun 17 '09 16:06

levi


People also ask

How do I make Tableview background transparent in Xcode?

Just select Clear Color on View Background for the table and for the cell also. Save this answer.

How do you make a transparent view in Swift?

Any SwiftUI view can be partially or wholly transparent using the opacity() modifier. This accepts a value between 0 (completely invisible) and 1 (fully opaque), just like the alpha property of UIView in UIKit.


2 Answers

If both the other options didn't work try this

UIView *backView = [[[UIView alloc] initWithFrame:CGRectZero] autorelease]; backView.backgroundColor = [UIColor clearColor]; cell.backgroundView = backView; 
like image 142
Ron Srebro Avatar answered Sep 21 '22 10:09

Ron Srebro


This is actually answered in the docs of UITableViewCell. So while you do have to setup transparency on your controls, the actual cell background color must be set per below.

"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."

https://developer.apple.com/documentation/uikit/uitableviewcell

like image 38
logancautrell Avatar answered Sep 21 '22 10:09

logancautrell