質問編集履歴
2
ソース全文を回答頂いた内容に更新
title
CHANGED
File without changes
|
body
CHANGED
@@ -24,8 +24,8 @@
|
|
24
24
|
self.taskList.tableHeaderView = headerView
|
25
25
|
```
|
26
26
|
|
27
|
-
###
|
27
|
+
###ソース
|
28
|
-
|
28
|
+
回答頂いたものをもとに更新しております。
|
29
29
|
```
|
30
30
|
import UIKit
|
31
31
|
|
@@ -33,10 +33,7 @@
|
|
33
33
|
|
34
34
|
override func viewDidLoad() {
|
35
35
|
super.viewDidLoad()
|
36
|
-
let headerView = self.taskList.tableHeaderView as UIView!
|
37
|
-
|
36
|
+
self.navigationItem.titleView = UIImageView(image:UIImage(named:"text_nav_title_today"))
|
38
|
-
self.taskList.tableHeaderView = headerView
|
39
|
-
|
40
37
|
}
|
41
38
|
|
42
39
|
override func didReceiveMemoryWarning() {
|
@@ -48,11 +45,10 @@
|
|
48
45
|
|
49
46
|
@IBOutlet weak var taskList: UITableView!
|
50
47
|
|
51
|
-
//
|
48
|
+
//データ
|
52
|
-
|
53
|
-
|
49
|
+
var taskTitles = [["task01","task02"],["task03"]]
|
54
|
-
|
50
|
+
var taskSubTitles = [["subtask01","subtask02"],["subtask03"]]
|
55
|
-
|
51
|
+
var taskSections:[String] = ["projectA","projectB"]
|
56
52
|
|
57
53
|
|
58
54
|
//テーブル定義
|
@@ -71,14 +67,32 @@
|
|
71
67
|
|
72
68
|
//section
|
73
69
|
func tableView(tableView:UITableView, titleForHeaderInSection section:Int) -> String?{
|
74
|
-
let label = UILabel(frame: CGRect(x:0, y:0, width: tableView.bounds.width, height: 50))
|
75
|
-
|
70
|
+
return taskSections[section]
|
76
|
-
label.backgroundColor = UIColor.redColor()
|
77
|
-
return label.text
|
78
71
|
}
|
79
72
|
|
80
73
|
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
|
81
74
|
return taskSections.count
|
82
|
-
}
|
75
|
+
}
|
76
|
+
|
77
|
+
|
78
|
+
// Section Header View
|
79
|
+
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
|
80
|
+
// HeaderのViewを作成してViewを返す
|
81
|
+
let headerView = UIView()
|
82
|
+
let label = UILabel()
|
83
|
+
label.text = "セクション"
|
84
|
+
label.textColor = UIColor.whiteColor()
|
85
|
+
headerView.backgroundColor = UIColor.redColor()
|
86
|
+
// いろいろ・・・
|
87
|
+
|
88
|
+
headerView.addSubview(label)
|
89
|
+
return view
|
90
|
+
}
|
91
|
+
|
92
|
+
// Section Header Height
|
93
|
+
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
|
94
|
+
// ヘッダーViewの高さを返す
|
95
|
+
return 40
|
96
|
+
}
|
83
97
|
}
|
84
98
|
```
|
1
キャプ等追加
title
CHANGED
@@ -1,1 +1,1 @@
|
|
1
|
-
|
1
|
+
UITableViewのセクションヘッダー背景/文字色を変更したい。
|
body
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
###前提・実現したいこと
|
2
|
-
現在swiftを勉強中です。
|
2
|
+
現在swiftを勉強中です。UITableViewでセクション分けとセクション部分のカスタマイズを行いたいのですが、具体的なやり方がわからず困っております。
|
3
3
|
具体的には、セクションの背景色と文字色を変更できればと考えております。
|
4
4
|
初歩的な質問かと思いますが、よろしくお願い致します。
|
5
5
|
|
6
|
+

|
7
|
+
|
6
8
|
###試したこと
|
7
9
|
①セクションにlabelを設定して、それの背景色を設定する、を試しましたがこの関数では、Stringしか返せず。
|
8
10
|
返り値をUIViewにすると「objective-C method~」のようなエラー表示。
|