//控件
var icon = UIImageView()
var title = UILabel()
override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
//控件实现
self.addSubview(icon)
self.addSubview(title)
}
//位置设置
override func layoutSubviews() {
super.layoutSubviews()
//图片框
let width = self.frame.width
let height = self.frame.height
let margin:CGFloat = 10.0//间距
let iconX = margin
let iconY = margin
let iconH = height - 2 * margin
let iconW = iconH * 1.2
icon.frame = CGRect(x: iconX, y: iconY, width: iconW, height: iconH)
icon.backgroundColor = UIColor.yellow
//文本框
let titleX = margin * 2 + iconW
let titleY = margin
let titleH = iconH
let titleW = width - titleX - margin
title.frame = CGRect(x: titleX, y: titleY, width: titleW, height: titleH)
title.backgroundColor = .red
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}