質問編集履歴

2

ソース全文を回答頂いた内容に更新

2017/02/12 10:15

投稿

Aki_1988
Aki_1988

スコア44

test CHANGED
File without changes
test CHANGED
@@ -50,9 +50,9 @@
50
50
 
51
51
 
52
52
 
53
- ###全文
53
+ ###ソース
54
54
 
55
- 関係ありそうな箇所のみ抜粋してます。
55
+ 回答頂いたもをもとに更新しております。
56
56
 
57
57
  ```
58
58
 
@@ -68,13 +68,7 @@
68
68
 
69
69
  super.viewDidLoad()
70
70
 
71
- let headerView = self.taskList.tableHeaderView as UIView!
72
-
73
- headerView.frame = CGRect(x: 0, y: 0, width: self.view.bounds.width, height: 500)
71
+ self.navigationItem.titleView = UIImageView(image:UIImage(named:"text_nav_title_today"))
74
-
75
- self.taskList.tableHeaderView = headerView
76
-
77
-
78
72
 
79
73
  }
80
74
 
@@ -98,15 +92,13 @@
98
92
 
99
93
 
100
94
 
101
- //テーブルデータ
95
+ //データ
102
96
 
103
-
97
+ var taskTitles = [["task01","task02"],["task03"]]
104
98
 
105
- var taskTitles = [["task01","task02"],["task03"]]
99
+ var taskSubTitles = [["subtask01","subtask02"],["subtask03"]]
106
100
 
107
- var taskSubTitles = [["subtask01","subtask02"],["subtask03"]]
108
-
109
- var taskSections:[String] = ["projectA","projectB"]
101
+ var taskSections:[String] = ["projectA","projectB"]
110
102
 
111
103
 
112
104
 
@@ -144,13 +136,7 @@
144
136
 
145
137
  func tableView(tableView:UITableView, titleForHeaderInSection section:Int) -> String?{
146
138
 
147
- let label = UILabel(frame: CGRect(x:0, y:0, width: tableView.bounds.width, height: 50))
148
-
149
- label.text = taskSections[section]
139
+ return taskSections[section]
150
-
151
- label.backgroundColor = UIColor.redColor()
152
-
153
- return label.text
154
140
 
155
141
  }
156
142
 
@@ -160,7 +146,49 @@
160
146
 
161
147
  return taskSections.count
162
148
 
163
- }
149
+ }
150
+
151
+
152
+
153
+
154
+
155
+ // Section Header View
156
+
157
+ func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
158
+
159
+ // HeaderのViewを作成してViewを返す
160
+
161
+ let headerView = UIView()
162
+
163
+ let label = UILabel()
164
+
165
+ label.text = "セクション"
166
+
167
+ label.textColor = UIColor.whiteColor()
168
+
169
+ headerView.backgroundColor = UIColor.redColor()
170
+
171
+ // いろいろ・・・
172
+
173
+
174
+
175
+ headerView.addSubview(label)
176
+
177
+ return view
178
+
179
+ }
180
+
181
+
182
+
183
+ // Section Header Height
184
+
185
+ func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
186
+
187
+ // ヘッダーViewの高さを返す
188
+
189
+ return 40
190
+
191
+ }
164
192
 
165
193
  }
166
194
 

1

キャプ等追加

2017/02/12 10:15

投稿

Aki_1988
Aki_1988

スコア44

test CHANGED
@@ -1 +1 @@
1
- UItableViewのセクション背景/文字色を変更したい。
1
+ UITableViewのセクションヘッダー背景/文字色を変更したい。
test CHANGED
@@ -1,10 +1,14 @@
1
1
  ###前提・実現したいこと
2
2
 
3
- 現在swiftを勉強中です。UItableViewでセクション分けとセクション部分のカスタマイズを行いたいのですが、具体的なやり方がわからず困っております。
3
+ 現在swiftを勉強中です。UITableViewでセクション分けとセクション部分のカスタマイズを行いたいのですが、具体的なやり方がわからず困っております。
4
4
 
5
5
  具体的には、セクションの背景色と文字色を変更できればと考えております。
6
6
 
7
7
  初歩的な質問かと思いますが、よろしくお願い致します。
8
+
9
+
10
+
11
+ ![イメージ説明](25e0ee6606dc44d073e6349c9240c556.png)
8
12
 
9
13
 
10
14