NewsTableViewCell.swift
class NewsTableViewCell: UITableViewCell {
//MARK:------------------UI控件-----------------------
var imgView: UIImageView? //图片视图
var titlelabel:UILabel? //标题标签
var dateLabel:UILabel? //时间标签
var authorLable:UILabel? //作者标签
//创建UI控件
func initUI() {
//图片视图
self.imgView = UIImageView.init(frame: CGRect.init(x: 5, y: 5, width: 140, height: 140))
self.contentView.addSubview(self.imgView!)
//标题标签
self.titlelabel = UILabel.init(frame: CGRect.init(x: 150, y: 5, width: srcW - 155, height: 100))
self.titlelabel?.font = UIFont.systemFont(ofSize: 20.0)
self.titlelabel?.numberOfLines = 3
self.contentView.addSubview(self.titlelabel!)
//时间标签
self.dateLabel = UILabel.init(frame: CGRect.init(x: 250, y: 125, width: srcW - 200, height: 13))
self.dateLabel?.font = UIFont.systemFont(ofSize: 14.0)
self.dateLabel?.textColor = UIColor.lightGray
self.contentView.addSubview(self.dateLabel!)
//作者标签
self.authorLable = UILabel.init(frame: CGRect.init(x: 150, y: 125, width: 150, height: 13))
self.authorLable?.font = UIFont.systemFont(ofSize: 14.0)
self.authorLable?.textColor = UIColor.lightGray
self.contentView.addSubview(self.authorLable!)
}
//MARK:------------------init-----------------------
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
self.initUI()
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
}
网友评论