Ios 仅在tableview单元格中设置左下角

Ios 仅在tableview单元格中设置左下角,ios,iphone,swift,uitableview,Ios,Iphone,Swift,Uitableview,我有个问题 我想把街角的景色做成这样,但我不知道怎么做: 我也回答了这个问题 所以我在layoutsubview中使用了角点函数 //var labelContent:UILabel override func layoutSubviews() { super.layoutSubviews() labelContent.roundCorners(corners: [.bottomLeft,.topLeft,.topRight], radius: 10) } 它可以工

我有个问题
我想把街角的景色做成这样,但我不知道怎么做:

我也回答了这个问题

所以我在layoutsubview中使用了角点函数

//var labelContent:UILabel

override func layoutSubviews() {
    super.layoutSubviews()
    labelContent.roundCorners(corners: [.bottomLeft,.topLeft,.topRight], radius: 10)


} 

它可以工作,但当我向上滚动时,单元格视图消失。
所以,我使用第二个函数。
但它也不起作用

更新:我遵循刺猬先生的建议:
当我向上滚动时,单元格视图消失。

 func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {

    guard let cell = cell as? ChatContentTableViewCell else { return }

    let maskPathTop = UIBezierPath(roundedRect: cell.contentView.bounds, byRoundingCorners: [.bottomRight], cornerRadii: CGSize(width: 0, height: 0))
    let shapeLayerTop = CAShapeLayer()
    shapeLayerTop.frame = cell.contentView.bounds
    shapeLayerTop.path = maskPathTop.cgPath
}

第二种解决方案不起作用,因为您正在实例化单元格的新实例,而不是使用回调提供的实例

将第一行更改为:

guard let cell=cell as?ChatContentTableViewCell else{return}


然后试试看。第二件事-你确定你需要更新标签的角,而不是保存它的内容视图吗

当我向上滚动时,单元格视图也消失了。我使用内容视图,什么也没有发生
    func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {

    let cell: ChatContentTableViewCell = ChatContentTableViewCell(style: .default, reuseIdentifier: nil)

    let maskPathTop = UIBezierPath(roundedRect: cell.bounds, byRoundingCorners: [.bottomRight], cornerRadii: CGSize(width: 0, height: 0))
    let shapeLayerTop = CAShapeLayer()
    shapeLayerTop.frame = cell.labelContent.bounds
    shapeLayerTop.path = maskPathTop.cgPath
}
 func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {

    guard let cell = cell as? ChatContentTableViewCell else { return }

    let maskPathTop = UIBezierPath(roundedRect: cell.contentView.bounds, byRoundingCorners: [.bottomRight], cornerRadii: CGSize(width: 0, height: 0))
    let shapeLayerTop = CAShapeLayer()
    shapeLayerTop.frame = cell.contentView.bounds
    shapeLayerTop.path = maskPathTop.cgPath
}