Ios Swift自定义TableViewCell(卡)
我正在尝试制作一张像Ios Swift自定义TableViewCell(卡),ios,swift,uitableview,pure-layout,Ios,Swift,Uitableview,Pure Layout,我正在尝试制作一张像cell一样的卡片(一张看起来像是自己在浮动的卡片)。现在,我只是想在单元格中显示一个红色的UIView(边距用12像素填充)。以下是来自UITableViewCell类的代码: import UIKit import PureLayout class MovieTableViewCell: UITableViewCell { let cardView = UIView() override init(style: UITableViewCellStyl
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")
}
}
目前我得到一个空白的
表格视图
。没有显示红色视图。任何人都知道我缺少的拼图部分(请注意,我使用的是PureLayout)tableView的contentView不能也不响应边距,它占据了tableView的整个宽度,您还必须使用auto layout来放置redView,使其延伸到其内容,或者使用
heightForRowAt
进行框架布局