创建控件
lazy var labelTop = { () -> UILabel in
let label = UILabel.init()
//label.textColor = TYBaseTools.UIColorFromRGB(rgbValue: 0x333333, alpha: 1)
label.text = "订单信息"
label.font = UIFont.systemFont(ofSize: 25)
return label
}()
将控件添加到cell上
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
self.addUI()
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
fatalError("init(coder:) has not been implemented")
}
func addUI() {
self.addSubview(self.labelTop)
//添加约束
self.labelTop.snp.makeConstraints { (make) in
make.top.leading.equalTo(self).offset(16)
make.height.equalTo(26)
}
}
完整代码如下
//
// Cell.swift
// Alamofire
//
// Created by xx on 2019/8/12.
//
import UIKit
class EntruckingCell: UITableViewCell {
lazy var labelTop = { () -> UILabel in
let label = UILabel.init()
label.textColor = TYBaseTools.UIColorFromRGB(rgbValue: 0x333333, alpha: 1)
label.text = "订单信息"
label.font = UIFont.systemFont(ofSize: 25)
return label
}()
override func awakeFromNib() {
super.awakeFromNib()
}
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
self.addUI()
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
fatalError("init(coder:) has not been implemented")
}
func addUI() {
self.addSubview(self.labelTop)
self.labelTop.snp.makeConstraints { (make) in
make.top.leading.equalTo(self).offset(16)
make.height.equalTo(26)
}
}
///数据填充
func fillViewWithData(data:Any) {
}
}