【问题标题】:tableviewCell is cut off from bottom in every celltableviewCell 在每个单元格中从底部切断
【发布时间】:2017-11-22 10:22:21
【问题描述】:

这是我的代码:

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;
}

每个单元格都从底部切掉,没有显示完整的单元格结构。

有什么想法吗?

【问题讨论】:

  • 如果图片没有显示,请告诉我。我是新来的。因此,如果您需要这方面的更多信息,请告诉我。
  • 你试过增加单元格的高度吗?
  • 降低whiteRoundedView的高度或增加单元格内容视图的高度。
  • 这个屏幕截图来自模拟器?或真实设备@GauravRathi
  • @byJeevan:它成功了,谢谢。我在初始化时将 whiteRoundedView 的高度降低到 40/

标签: ios uitableview cell tableviewcell


【解决方案1】:

whiteRoundedView 超出单元格高度的空间不足。

因此,在初始化时减小 whiteRoundedView 的高度

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

【讨论】:

    【解决方案2】:

    您的whiteRoundedView 应该在单元格内容视图中。

    所以,尝试使用heightForRowAt indexPath 并在willDisplay cell 中为whiteRoundedView 使用相同的高度

    【讨论】:

      猜你喜欢
      • 2015-01-08
      • 1970-01-01
      • 1970-01-01
      • 2021-04-03
      • 2021-06-10
      • 1970-01-01
      • 1970-01-01
      • 2014-09-23
      • 1970-01-01
      相关资源
      最近更新 更多