【发布时间】:2015-07-26 06:17:17
【问题描述】:
我有一个我使用的标题数组
let sectionHeaderTitleArray = ["test1","test2","test3]
它们显示使用
func tableView[tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
return self.sectionHeaderTitleArray[section] as String
}
现在所有这些都可以正常工作,但我想修改标题的背景颜色,以便它们更明显(深色)
任何想法,如果我可以在一个简单的行中做到这一点,或者我是否需要使用自定义单元格来创建这个
谢谢
更新
//number of sections and names for the table
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return self.sectionHeaderTitleArray.count
}
func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
return self.sectionHeaderTitleArray[section] as String
}
func tableView(tableView: UITableView, ViewForHeaderInSection section: Int) -> UIView? {
return self.tableView.backgroundColor = UIColor.lightGrayColor()
}
【问题讨论】:
-
好吧,当它需要一个 UIView 时,你正在返回一个 UIColor..
-
你需要用returnedView.backgroundColor = UIColor.lightGrayColor() 来设置,这里returnedView是你在func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView中初始化的UIView?
-
查看我的更新答案
-
您将不得不根据您使用的数据手动计算 y 值,x 值可以为 0,宽度值为 UIScreen.mainScreen().bounds.size.width 和高度将在 10.0 左右(根据自己的喜好玩)
标签: ios uitableview swift ios8