2016-07-28 62 views
2

我將TableView從Plain更改爲Grouped,以便頁眉/頁腳不會浮動在表上並保持錨定在表的頂部和底部。這很簡單,但現在我設置的字體樣式格式不起作用。奇怪的是,頁眉/頁腳的所有其他格式似乎都在工作。任何關於發生了什麼事以及我失蹤的想法都會很感激!下面分組表中的TableView頁眉/頁腳字體(Swift)

代碼:

// Setup format of the header 
func tableView(tableView: UITableView, willDisplayHeaderView view: UIView, forSection section: Int) { 

    let title = UILabel() 
    title.font = UIFont(name: "Avenir Book", size: 12) 
    title.textColor = UIColor.whiteColor() 


    let header: UITableViewHeaderFooterView = view as! UITableViewHeaderFooterView 
    header.contentView.backgroundColor = UIColor(red: 30/255, green: 30/255, blue: 50/255, alpha: 1) 
    header.textLabel!.font = title.font 
    header.textLabel?.textColor = title.textColor 
    header.textLabel?.numberOfLines = 0 
    header.textLabel?.lineBreakMode = NSLineBreakMode.ByWordWrapping 
    header.textLabel?.textAlignment = NSTextAlignment.Center 

} 

在一個普通的表上述所有的偉大工程,是這樣的:

enter image description here

然而,當我更改爲分組表的所有格式的似乎顯示除了字體樣式這個這個:

I am puzzled about where the ALL CAPS is coming from

我對所有CAPS來自哪裏感到困惑。

我試圖從this question/answer實施解決方案,但無法讓它工作。感謝您的想法!

回答

2

假設你在這個方法中提供的字符串該部分的標題:

func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? { 

但在分組的tableview,該字符串更改爲全部大寫。要刪除全部大寫,嘗試添加在willDisplayHeaderView方法這兩行之一:

header.textLabel?.text = header.textLabel!.text!.capitalizedString 
header.textLabel?.text = header.textLabel!.text!.lowercaseString 

第一個將大寫每個單詞的第一個字母,第二個會做一切小寫。如果你不想要那些你可以直接添加的字符串:

header.textLabel?.text = "Here are a few options for you. Select to learn more" 
+0

啊有道理!非常感謝!我選擇將字符串添加到titleForHeaderInSection中以保留句子大小寫。 – Ben