@@ -66,7 +66,18 @@ class TokenListViewController: UITableViewController {
66
66
return label
67
67
} ( )
68
68
69
- fileprivate let warningLabel : UILabel = {
69
+ fileprivate lazy var noTokensButton : UIButton = {
70
+ let button = UIButton ( type: . custom)
71
+ button. addTarget ( self , action: #selector( addToken) , for: . touchUpInside)
72
+
73
+ self . noTokensLabel. frame = button. bounds
74
+ self . noTokensLabel. autoresizingMask = [ . flexibleWidth, . flexibleHeight]
75
+ button. addSubview ( self . noTokensLabel)
76
+
77
+ return button
78
+ } ( )
79
+
80
+ fileprivate let backupWarningLabel : UILabel = {
70
81
let linkTitle = " Learn More → "
71
82
let message = " For security reasons, tokens will be stored only on this \( UIDevice . current. model) , and will not be included in iCloud or unencrypted backups. \( linkTitle) "
72
83
let paragraphStyle = NSMutableParagraphStyle ( )
@@ -89,8 +100,14 @@ class TokenListViewController: UITableViewController {
89
100
return label
90
101
} ( )
91
102
92
- private let warningButton : UIButton = {
103
+ fileprivate lazy var backupWarning : UIButton = {
93
104
let button = UIButton ( type: . custom)
105
+ button. addTarget ( self , action: #selector( showBackupInfo) , for: . touchUpInside)
106
+
107
+ self . backupWarningLabel. frame = button. bounds
108
+ self . backupWarningLabel. autoresizingMask = [ . flexibleWidth, . flexibleHeight]
109
+ button. addSubview ( self . backupWarningLabel)
110
+
94
111
return button
95
112
} ( )
96
113
@@ -128,27 +145,9 @@ class TokenListViewController: UITableViewController {
128
145
]
129
146
self . navigationController? . isToolbarHidden = false
130
147
131
- // Configure "no tokens" label
132
- self . noTokensLabel. frame = CGRect (
133
- x: 0 ,
134
- y: 0 ,
135
- width: self . view. bounds. size. width,
136
- height: self . view. bounds. size. height * 0.6
137
- )
138
- self . view. addSubview ( self . noTokensLabel)
139
-
140
- let labelMargin : CGFloat = 20
141
- let labelSize = warningLabel. sizeThatFits ( view. bounds. insetBy ( dx: labelMargin, dy: labelMargin) . size)
142
- let labelOrigin = CGPoint ( x: labelMargin, y: view. bounds. maxY - labelMargin - labelSize. height)
143
- warningLabel. frame = CGRect ( origin: labelOrigin, size: labelSize)
144
- warningLabel. autoresizingMask = [ . flexibleTopMargin, . flexibleWidth]
145
- view. addSubview ( warningLabel)
146
-
147
- let warningButton = UIButton ( )
148
- warningButton. frame = warningLabel. frame
149
- warningButton. autoresizingMask = warningLabel. autoresizingMask
150
- warningButton. addTarget ( self , action: #selector( showBackupInfo) , for: . touchUpInside)
151
- view. addSubview ( warningButton)
148
+ // Configure empty state
149
+ view. addSubview ( noTokensButton)
150
+ view. addSubview ( backupWarning)
152
151
153
152
infoButton. addTarget ( self , action: #selector( TokenListViewController . showLicenseInfo) , for: . touchUpInside)
154
153
@@ -169,6 +168,21 @@ class TokenListViewController: UITableViewController {
169
168
self . isEditing = false
170
169
}
171
170
171
+ override func viewWillLayoutSubviews( ) {
172
+ super. viewWillLayoutSubviews ( )
173
+
174
+ let labelMargin : CGFloat = 20
175
+ let insetBounds = view. bounds. insetBy ( dx: labelMargin, dy: labelMargin)
176
+ let noTokensLabelSize = noTokensLabel. sizeThatFits ( insetBounds. size)
177
+ let noTokensLabelOrigin = CGPoint ( x: ( view. bounds. width - noTokensLabelSize. width) / 2 ,
178
+ y: ( view. bounds. height * 0.6 - noTokensLabelSize. height) / 2 )
179
+ noTokensButton. frame = CGRect ( origin: noTokensLabelOrigin, size: noTokensLabelSize)
180
+
181
+ let labelSize = backupWarningLabel. sizeThatFits ( insetBounds. size)
182
+ let labelOrigin = CGPoint ( x: labelMargin, y: view. bounds. maxY - labelMargin - labelSize. height)
183
+ backupWarning. frame = CGRect ( origin: labelOrigin, size: labelSize)
184
+ }
185
+
172
186
// MARK: Target Actions
173
187
174
188
func addToken( ) {
@@ -262,8 +276,8 @@ extension TokenListViewController {
262
276
263
277
tableView. isScrollEnabled = viewModel. hasTokens
264
278
editButtonItem. isEnabled = viewModel. hasTokens
265
- noTokensLabel . isHidden = viewModel. hasTokens
266
- warningLabel . isHidden = viewModel. hasTokens
279
+ noTokensButton . isHidden = viewModel. hasTokens
280
+ backupWarning . isHidden = viewModel. hasTokens
267
281
268
282
// Exit editing mode if no tokens remain
269
283
if self . isEditing && viewModel. rowModels. isEmpty {
0 commit comments