UITableViewHeader背景颜色未完全更改

时间:2015-11-04 04:25:12

标签: ios swift

我正在尝试更改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()
}

enter image description here

那么这里有什么问题?

编辑:似乎大多数人都无法理解这个问题。请查看上面的更新图片。当有一个选择索引时(你在侧面看到的那些字母,那么标题的背景颜色不会一直延伸到右边。相反,它只会停留在90%左右,然后你会看到浅紫色(指出的是什么。

1 个答案:

答案 0 :(得分:4)

尝试

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()

这是我测试的 enter image description here

<强>更新

您可以设置正确的颜色,但是部分索引视图位于部分标题

的顶部

viewDidLoad

中添加此行
 tableView.sectionIndexBackgroundColor = UIColor.clearColor()
相关问题