如何在titleForHeaderInSection中设置颜色? -迅速
发布时间:2020-12-14 04:36:30 所属栏目:百科 来源:网络整理
导读:我的tableview中有两个部分,我想为tableView的不同sectionHeaders设置不同的颜色,我该怎么做? func tableView(tableView: UITableView!,titleForHeaderInSection section: Int) - String! { if (section == 0) { return "Item1" } if (section == 1) { retu
我的tableview中有两个部分,我想为tableView的不同sectionHeaders设置不同的颜色,我该怎么做?
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 } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |