如果Controller 继承的是 UIViewController 则需要继承 .....- -! 遵守协议 UITableViewDataSource, UITableViewDelegate.并在 viewDidLoad 中:
tableView.dataSource = self
tableView.delegate = self
//移除 Cell 全部分割线
tableView.separatorStyle = .none
//预设行高
tableView.estimatedRowHeight = 20
//自动设置高度
tableView.rowHeight = UITableViewAutomaticDimension
/*----- 列表由下向上----*/
1: tableView.transform = CGAffineTransform (scaleX: 1,y: -1)
2: var index = self.textList.count-1-indexPath.row
3: let content = textList[index]
4: cell.content.transform = CGAffineTransform (scaleX: 1,y: -1)
//cell 中 label 自动换行
cell.content.lineBreakMode = NSLineBreakMode.byWordWrapping
cell.content.numberOfLines = 0
//cell 文字多段变色
var cellName = content.name + ": "
var celltext = content.content
//所有文字变为富文本
let attrstring:NSMutableAttributedString = NSMutableAttributedString(string: cellName + celltext)
//颜色处理的范围
let str = NSString(string: cellName + celltext)
let theRange = str.range(of: cellName)
//颜色处理
attrstring.addAttribute(NSAttributedStringKey.foregroundColor, value:UIColor.red, range: theRange)
cell.content.attributedText = attrstring
/*
将按钮视图设置到cell视图顶层
*/
func bringBtnToFront() {
view.bringSubview(toFront: 控件名)
}