我正在尝试制作一张类似卡片的卡片cell
(看起来像是自己漂浮的卡片)。现在,我只是想让一个红色UIView
出现在单元格内(为边距填充 12 个像素)。这是该UITableViewCell
课程的代码:
import UIKit
import PureLayout
class MovieTableViewCell: UITableViewCell {
let cardView = UIView()
override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
var margins = layoutMargins
margins.left = 12
margins.top = 12
margins.right = 12
margins.bottom = 12
contentView.layoutMargins = margins
cardView.backgroundColor = UIColor.red
contentView.addSubview(cardView)
contentView.backgroundColor = nil
contentView.preservesSuperviewLayoutMargins = false
cardView.autoPinEdgesToSuperviewMargins()
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
目前我得到一个空白tableView
。没有红色视图出现。任何人都知道我缺少的那块拼图(PS 我正在使用 PureLayout)