我的tableview中有两个部分,我想为tableView的不同sectionHeaders设置不同的颜色,我该怎么做? func tableView(tableView: UITableView!, titleForHeaderInSection section: Int) - String! { if (section == 0) { return "Item1"
func tableView(tableView: UITableView!, titleForHeaderInSection section: Int) -> String! {
if (section == 0) {
return "Item1"
}
if (section == 1) {
return "Item2"
}
}
与Objective-C中的方式相同:提供带标签的自定义标题并更改其文本颜色
override func tableView(tableView: UITableView!, viewForHeaderInSection section: Int) -> UIView! {
var label : UILabel = UILabel()
if(section == 0){
label.text = "Item1"
} else if (section == 1){
label.textColor = UIColor.orangeColor()
label.text = "Item2"
}
return label
}
