How do I make this UITableView clear (transparent) in Swift 3
You can try this
In viewDidLoad:
tableView.backgroundColor = UIColor.clear
In cellForRowAt:
cell.contentView.backgroundColor = UIColor.clear
It's work for me.
Note: Below code been tested in Swift 3
.
Method 1:
Select your tableViewCell from your storyboard
and goto Attributes Inspector
under View
change Background
to clear
Method 2: Try below code inside your cellForRowAt
cell.layer.backgroundColor = UIColor.clear.cgColor
Note : If above method didn't works.try clear your project build by pressing shift + option + command + k
Update: Update your cellForRowAt
from below code...
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath as IndexPath)
cell.textLabel?.text = communities[indexPath.row]
cell.textLabel?.font = UIFont(name: "Avenir", size: 12)
cell.textLabel?.textColor = UIColor.red // set to any colour
cell.layer.backgroundColor = UIColor.clear.cgColor
return cell
}
You have to set both table and cell background clear.
Inside tableView function:
tableView.backgroundColor = .clear
cell.backgroundColor = .clear
tableView.tableFooterView = UIView()
The two first answer doesn't work for me so I add a clear background everywhere and the white bg go away.
cell.layer.backgroundColor = UIColor.clear.cgColor
cell.backgroundColor = .clear
tableView.layer.backgroundColor = UIColor.clear.cgColor
tableView.backgroundColor = .clear
SWIFT 5.5.3