直接写在cell中
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
//自定义cell样式1
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
let dp = UILabel.init(frame: CGRect.init(x: 80, y: 20, width: 250, height: 30))
dp.text=“随意吧什么鬼”
self.addSubview(dp)
// let spck = UILabel.init(frame: CGRect.init(x: 300, y: 5, width: 100, height: 40))
// spck.textColor=UIColor.red
// spck.text=“商品出库”
// self.addSubview(spck)
let wlxx = UILabel.init(frame: CGRect.init(x: 80, y: 50, width: 350, height: 90))
wlxx.numberOfLines=0
wlxx.text=“上来看到飞机奥数的金发少女胸围杀了多久佛瓷碗搜洒进来的佛琼儿”
self.addSubview(wlxx)
let sj = UILabel.init(frame: CGRect.init(x: 80, y: 30, width: 350, height: 40))
sj.text=“2018年12月21日”
sj.textColor=UIColor.lightGray
self.addSubview(sj)
let img = UIImageView.init(frame: CGRect.init(x: 10, y: 20, width: 60, height: 60))
img.image=UIImage.init(named: “07”)
self.addSubview(img)
let img1 = UIImageView.init(frame: CGRect.init(x:7, y: 120, width: 400, height: 130))
img1.image=UIImage.init(named: “07”)
self.addSubview(img1)
// let xx = UILabel.init(frame: CGRect.init(x: 130, y: 120, width: 250, height: 90))
// xx.numberOfLines=0
// xx.text=“上来看到飞机奥数的金发少女胸围杀了多久佛瓷碗搜洒进来的佛琼儿”
// self.addSubview(xx)
let sp = UILabel.init(frame: CGRect.init(x: 180, y: 210, width: 100, height: 40))
sp.text=“共计1件商品”
self.addSubview(sp)
let jp = UILabel.init(frame: CGRect.init(x: 280, y: 210, width: 120, height: 40))
jp.text=“付款 $323.00”
self.addSubview(jp)
let btn = UIButton.init(frame: CGRect.init(x: 200, y: 250, width: 90, height: 40))
btn.backgroundColor=UIColor.yellow
btn.setTitle(“再次购买”, for: UIControl.State.normal)
btn.setTitleColor(UIColor.black, for: UIControl.State.normal)
self.addSubview(btn)
let btn1 = UIButton.init(frame: CGRect.init(x: 300, y: 250, width: 90, height: 40))
btn1.backgroundColor=UIColor.yellow
btn1.setTitle(“查看物流”, for: UIControl.State.normal)
btn1.setTitleColor(UIColor.black, for: UIControl.State.normal)
self.addSubview(btn1)
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
在oneviewcontroller中写表格的注册
class OneViewController: UIViewController,UITableViewDelegate,UITableViewDataSource {
//设置cell个数
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 5
}
//设置cell 内容
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell1 = tableView.dequeueReusableCell(withIdentifier: “cellone”)
let cell2 = tableView.dequeueReusableCell(withIdentifier: “celltwo”)
let cell3 = tableView.dequeueReusableCell(withIdentifier: “cellthree”)
if indexPath.row0 {
tableView.rowHeight=300
return cell1!
}else if indexPath.row1{
tableView.rowHeight=250
return cell2!
}else if indexPath.row==3{
tableView.rowHeight=300
return cell1!
}
else{
tableView.rowHeight=250
return cell3!
}
}
//懒加载
private lazy var tbv:UITableView = {
var table=UITableView()
table=UITableView.init(frame: self.view.frame, style: UITableView.Style.plain)
table.delegate=self
table.dataSource=self
return table
}()
//添加
override func viewDidLoad() {
super.viewDidLoad()
view.addSubview(tbv)
//注册cell
tbv.register(OneTableViewCell.self, forCellReuseIdentifier: “cellone”)
tbv.register(TwoTableViewCell.self, forCellReuseIdentifier: “celltwo”)
tbv.register(ThreeTableViewCell.self, forCellReuseIdentifier: “cellthree”)
}
}