2015-11-04 29 views
1

我想改變iOS應用程序(Swift)中每個部分標題的背景顏色。雖然大部分內容都是由以下代碼改變的,但右側有一個小間隙(見下圖),它沒有改變。我該如何改變它?UITableViewHeader背景顏色沒有完全改變

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%,然後您會看到淺紫色(什麼被指出)。

回答

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

返回相同的結果。它仍然不完全是紫色,右側仍然有淺灰色。用sectionIndex進行測試。 – DemCodeLines

+0

看看我更新 – Leo

+0

這樣做!謝謝! – DemCodeLines