自定义cell其实还是比较简单的,个人理解,直接把自己需要的控件添加为子视图就行了。
下面直接给出简单代码块:
TableViewCell.swift代码块如下:
class TableViewCell: UITableViewCell {
var title:UILabel!
var clickBtn:UIButton!
override func awakeFromNib() {
super.awakeFromNib()
}
override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
if !self.isEqual(nil) {
title = UILabel(frame: CGRectMake(20, 20, 200, 30))
self.contentView.addSubview(title)
clickBtn = UIButton(frame: CGRectMake(200, 20, 60, 30))
clickBtn.setTitle("app", forState: UIControlState.Normal)
clickBtn.setTitleColor(UIColor.blueColor(), forState: UIControlState.Normal)
clickBtn.setTitleColor(UIColor.whiteColor(), forState: UIControlState.Highlighted)