首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

Swift UITableViewCell边框在删除时变得有角度

是因为UITableViewCell的默认删除样式是带有角度的。当我们调用deleteRows(at:with:)方法删除某一行时,UITableViewCell会根据默认的删除样式进行动画效果的展示。

要解决这个问题,我们可以通过自定义UITableViewCell的删除样式来改变边框的角度。具体步骤如下:

  1. 创建一个自定义的UITableViewCell子类,例如CustomTableViewCell。
  2. 在CustomTableViewCell类中重写layoutSubviews()方法,该方法会在cell布局发生变化时被调用。
  3. 在layoutSubviews()方法中,设置cell的contentView.layer.cornerRadius属性为0,这样就可以去除边框的角度。
  4. 在UITableViewDelegate的willDisplay(_:forRowAt:)方法中,将要显示的cell的删除样式设置为.none,以避免默认的带角度的删除样式。

下面是示例代码:

代码语言:txt
复制
class CustomTableViewCell: UITableViewCell {
    override func layoutSubviews() {
        super.layoutSubviews()
        contentView.layer.cornerRadius = 0
    }
}

class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
    // ...

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "CustomCell", for: indexPath) as! CustomTableViewCell
        // 配置cell的内容
        return cell
    }

    func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
        cell.selectionStyle = .none
    }

    // ...
}

通过以上步骤,我们可以解决UITableViewCell边框在删除时变得有角度的问题。

推荐的腾讯云相关产品:腾讯云移动开发平台(https://cloud.tencent.com/product/mpp)可以帮助开发者快速构建移动应用,提供丰富的移动开发工具和服务。

页面内容是否对你有帮助?
有帮助
没帮助

相关·内容

没有搜到相关的沙龙

领券