https://blog.csdn.net/potato512/article/details/52911957
1.tableviewcell 的封装
class celltest: UITableViewCell {
class func tableviewBack(tableV:UITableView) -> celltest {
let cellid = "celltest"
var cell:celltest!
if let cellBeforWarrp = tableV.dequeueReusableCell(withIdentifier: cellid) as? celltest{
cell = cellBeforWarrp
}else{
cell = celltest.init(style: UITableViewCell.CellStyle.default, reuseIdentifier: cellid)
}
cell.selectionStyle = UITableViewCell.SelectionStyle.none
cell.backgroundColor = UIColor.red
return cell
}
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
self.creatUI()
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func creatUI(){
let lab = UILabel()
self.contentView.addSubview(lab)
lab.font = UIFont.systemFont(ofSize: 14)
lab.text = "swift 学习";
lab.snp.makeConstraints { (make) in
make.size.equalTo(CGSize(width: 100, height: 20));
make.centerY.equalToSuperview()
make.left.equalTo(self.contentView).offset(20)
}
}
}