回答編集履歴

2

テーブルのヘッダ/フッタを使う方法を追加。

2016/04/28 01:31

投稿

fuzzball
fuzzball

スコア16731

test CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
 
4
4
 
5
- 【追記】
5
+ #やってみる
6
6
 
7
7
 
8
8
 
9
- ヘッダフッタを使って実現してみました。
9
+ #####セクションのヘッダ/フッタを使
10
10
 
11
11
 
12
12
 
@@ -66,6 +66,48 @@
66
66
 
67
67
 
68
68
 
69
+ #####テーブルのヘッダ/フッタを使う
70
+
71
+
72
+
73
+ こっちの方がシンプルで良さげ。
74
+
75
+
76
+
77
+ ```swift
78
+
79
+ class ViewController: UIViewController {
80
+
81
+
82
+
83
+ @IBOutlet weak var table: UITableView!
84
+
85
+
86
+
87
+ override func viewDidLoad() {
88
+
89
+ super.viewDidLoad()
90
+
91
+
92
+
93
+ let frame = CGRectMake(0, 0, CGRectGetWidth(table.frame), 1/*お好きな高さに*/)
94
+
95
+ table.tableHeaderView = UIView(frame: frame)
96
+
97
+ table.tableFooterView = UIView(frame: frame)
98
+
99
+ table.tableHeaderView!.backgroundColor = UIColor.greenColor() //お好きな色に
100
+
101
+ table.tableFooterView!.backgroundColor = UIColor.orangeColor() //
102
+
103
+ }
104
+
105
+ :
106
+
107
+ }
108
+
109
+ ```
110
+
69
111
  #できあがり
70
112
 
71
113
 

1

ヘッダとフッタ。

2016/04/28 01:31

投稿

fuzzball
fuzzball

スコア16731

test CHANGED
@@ -1 +1,73 @@
1
1
  現在、実際に試せないのですが、ヘッダやフッタ、もしくはセクションを使って実現できないでしょうか?
2
+
3
+
4
+
5
+ 【追記】
6
+
7
+
8
+
9
+ ヘッダとフッタを使って実現してみました。
10
+
11
+
12
+
13
+ ```swift
14
+
15
+ //ヘッダ(上の線)
16
+
17
+ func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
18
+
19
+ let view = UIView()
20
+
21
+ view.backgroundColor = UIColor.greenColor() //お好きな色に
22
+
23
+ return view
24
+
25
+ }
26
+
27
+
28
+
29
+ //フッタ(下の線)
30
+
31
+ func tableView(tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
32
+
33
+ let view = UIView()
34
+
35
+ view.backgroundColor = UIColor.orangeColor() //お好きな色に
36
+
37
+ return view
38
+
39
+ }
40
+
41
+
42
+
43
+ //ヘッダの高さ(上の線の幅)
44
+
45
+ func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat
46
+
47
+ {
48
+
49
+ return 1 //お好きな高さに
50
+
51
+ }
52
+
53
+
54
+
55
+ //フッタの高さ(下の線の幅)
56
+
57
+ func tableView(tableView: UITableV![イメージ説明](344a0bbcf888030f87c495bcc129513b.png)説明](7de0ad87abd0c7a94bf82d726fab393f.png)eightForFooterInSection section: I![イメージ説明](26b361b44483da144758a3fd28f2ec62.png) CGFloat
58
+
59
+ {
60
+
61
+ return 1 //お好きな高さに
62
+
63
+ }
64
+
65
+ ```
66
+
67
+
68
+
69
+ #できあがり
70
+
71
+
72
+
73
+ ![table with border](bbee291ca5e2310c6d90edf9ba637714.png)