ios - UITableView 标题背景颜色没有完全改变

标签 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%,然后你会看到浅紫色(指的是什么)。

最佳答案

尝试

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

更新

你设置了正确的颜色,但是章节索引 View 在章节标题的顶部

viewDidLoad中添加这一行

 tableView.sectionIndexBackgroundColor = UIColor.clearColor()

关于ios - UITableView 标题背景颜色没有完全改变,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33513681/

相关文章:

ios - iOS 6.1 状态栏字体变化

ios - 如何以编程方式获取 iOS 的字母数字版本字符串

ios - 在 UICollectionView 中将单元格居中(水平)对齐

ios - SLComposeServiceViewController高度问题

ios - Swift ResearchKit makePDFWithCompletionHandler

ios - Swift 不平衡调用开始/结束外观转换

ios - 如何获取 Apple Watch 硬件标识符?

swift - 避免在受约束的字符集中出现双周期崩溃

swift - 我们可以在枚举上使用 `if` 或 `guard` 而不是 `switch` 来提取值吗?

swift - 如何有条件地在协议(protocol)扩展方法实现之间切换?