回答
你必須爲此在UITableView的數據源方法viewForHeaderInSection
:
雨燕2.3:
func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let headerText = UILabel()
headerText.textColor = UIColor.lightGrayColor()
headerText.adjustsFontSizeToFitWidth = true
switch section{
case 0:
headerText.textAlignment = .Center
headerText.text = "This Header Will Be Centered"
case 1:
headerText.textAlignment = .Right
headerText.text = "This Header Will Be Aligned Right"
default:
headerText.textAlignment = .Left
headerText.text = "Default Will Be Left"
}
return headerText
}
編輯:修改了上面的代碼。您可以使用section
參數來標識要修改的部分。
我得到這個錯誤:致命錯誤:意外地發現零,同時展開一個可選值 –
只是更新的代碼。 –
它部分工作...現在我的所有部分都有該標題文本,但我想只在其中一些標題文本中,並自定義文本以及它們中的每一個。 +我想要我的原始灰色,如果我可以問:D –
斯威夫特4
func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
return "Your Header Name"
}
func tableView(_ tableView: UITableView, willDisplayHeaderView view: UIView, forSection section: Int) {
let header: UITableViewHeaderFooterView = view as! UITableViewHeaderFooterView
header.textLabel?.font = UIFont(name: "YourFontname", size: 14.0)
header.textLabel?.textAlignment = NSTextAlignment.right
}
它完美地工作! IMO比標記的答案更好 –
- 1. 網絡攝像頭校準
- 2. 使用MATLAB攝像機校準器進行單鏡頭校準的問題
- 3. 通用網絡攝像頭校準
- 4. 手動校準安卓攝像頭
- 5. 非平面鑽機鏡頭校準
- 6. OpenCV和python校準攝像頭
- 7. 變化anythingslider箭頭對準距離
- 8. 校準Opencv
- 9. android GPS校準
- 10. 參數校準
- 11. Sphero API校準
- 12. 圖像陣列,子彈時間校準
- 13. 確定相機校準的校準板的適當尺寸
- 14. MATLAB估計未經校準的校準非確定性行爲
- 15. 校準我的攝像頭,支持OpenCV的
- 16. 攝像機校準
- 17. 觸摸屏校準
- 18. OpenCV校準代碼
- 19. 指南針校準
- 20. findChessboardCorners校準失敗
- 21. 相機校準庫
- 22. Netbeans JDK校準8.1
- 23. OpenCV的OpenNI校準Kinect的
- 24. 校驗和檢測的變化
- 25. glsl和變化值的透視校正
- 26. 隨着系統時區的變化,VCal時間變化
- 27. python和opencv的校準
- 28. WinCE中的屏幕校準
- 29. 相機校準的疑問
- 30. 的Android的TableView頭
你用斯威夫特2個或3個工作? –
@GeorgeH斯威夫特2.3 –
@GeorgeH我有一些奇怪的間距問題,你可以嘗試和幫助我嗎? –