我正在尝试更改 iOS 应用程序 (Swift) 中每个部分标题的背景颜色。虽然大部分内容已被以下代码更改,但右侧有一个小间隙(见下图)未更改。我该如何改变它?
override func tableView(tableView: UITableView, willDisplayHeaderView view: UIView, forSection section: Int) {
view.tintColor = UIColor(red: 91.0 / 255.0, green: 102.0 / 255.0, blue: 243.0 / 255.0, alpha: 1.0)
let header = view as! UITableViewHeaderFooterView
header.textLabel?.textColor = UIColor.whiteColor()
}
那么这里有什么问题呢?
编辑:似乎大多数人都无法理解这个问题。查看上面的更新图像。当有一个选择索引(你在侧面看到的那些字母表时,标题的背景颜色不会一直延伸到右边。相反,它只是停在大约 90%,然后你会看到浅紫色(指的是什么)。
最佳答案
尝试
let header = view as! UITableViewHeaderFooterView
header.backgroundView?.backgroundColor = UIColor(red: 91.0 / 255.0, green: 102.0 / 255.0, blue: 243.0 / 255.0, alpha: 1.0)
header.textLabel?.textColor = UIColor.whiteColor()
更新
你设置了正确的颜色,但是章节索引 View 在章节标题的顶部
在viewDidLoad
中添加这一行
tableView.sectionIndexBackgroundColor = UIColor.clearColor()
关于ios - UITableView 标题背景颜色没有完全改变,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33513681/