2016-07-28 26 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