【发布时间】:2018-01-29 19:55:15
【问题描述】:
我已经为 UITableViewCell 画了一个边框
我必须为 UITableViewCell 设置前导和尾随约束,以便边框看起来正确。
要绘制边框,我在cellForRowAt(:)使用了以下代码
let today = tableView.dequeueReusableCell(withIdentifier: "todo", for: indexPath) as! DisplayTODOTaskCell
today.layer.masksToBounds = true
today.layer.cornerRadius = 0
today.layer.borderWidth = 1
today.layer.shadowOffset = CGSize(width: -1, height: 1)
let borderColor: UIColor = .black
today.layer.borderColor = borderColor.cgColor
当我使用下面的代码时,我遇到了运行时错误。
today.constraints(NSLayoutConstraint(item: today, attribute: .alignAllLeading, relatedBy: nil, toItem: self, attribute: self, multiplier: 1, constant: 10))
当我从手机查看时左右边框不可见。
我用过 TableViewController。
我可以通过留出空间来绘制单元格的边框。
需要我为不同部分的后续单元格实现,为此我需要知道上一个部分的高度。请告诉我如何实现这一点
我在 UITableViewCell 类中添加了以下代码。 覆盖 func layoutSubviews() { self.frame = CGRect(x: 10.0, y: 5.0, width: 390.0, height: self.frame.size.height) print("1111 高度 = (self.frame.size.height)") super.layoutSubviews() }
【问题讨论】:
-
您需要出示您的代码,以便我们为您提供指导。到目前为止,您尝试过什么?
标签: ios swift uitableview autolayout