Search code examples
ioscelluitableview

tableviewCell is cut off from bottom in every cell


Here is my code:

override func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
    let whiteRoundedView : UIView = UIView(frame: CGRect(x: 10, y: 8, width: self.view.frame.size.width - 20, height: 140))

    whiteRoundedView.layer.backgroundColor = CGColor(colorSpace: CGColorSpaceCreateDeviceRGB(), components: [1.0, 1.0, 1.0, 0.9])
    whiteRoundedView.layer.masksToBounds = false
    whiteRoundedView.layer.cornerRadius = 2.0
    whiteRoundedView.layer.shadowOffset = CGSize(width: -1, height: 1)
    whiteRoundedView.layer.shadowOpacity = 0.2
    whiteRoundedView.layer.borderWidth = 0.5
    whiteRoundedView.layer.borderColor = UIColor.orange.cgColor
    cell.contentView.backgroundColor = UIColor.clear
    cell.contentView.addSubview(whiteRoundedView)
    cell.contentView.sendSubview(toBack: whiteRoundedView)
    cell.accessoryType = .disclosureIndicator
    cell.clipsToBounds = true;
}

Every cell is cut off from the bottom and not showing the complete cell structure.

enter image description here

Any idea?


Solution

  • There is not enough space for the whiteRoundedView over cell height.

    Hence, reduce the height <140 of whiteRoundedView while initialization.

    let whiteRoundedView : UIView = UIView(frame: CGRect(x: 10, y: 8, width:self.view.frame.size.width - 20, height: YOUR_NEW_HEIGHT))