質問編集履歴
1
コードを追加いたしました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,4 +1,280 @@
|
|
1
|
+
```swift
|
2
|
+
|
3
|
+
|
4
|
+
|
5
|
+
import UIKit
|
6
|
+
|
7
|
+
import SwiftUI
|
8
|
+
|
9
|
+
import Firebase
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
class EditorViewController: UIViewController, UIColorPickerViewControllerDelegate, UITextFieldDelegate{
|
14
|
+
|
15
|
+
|
16
|
+
|
17
|
+
@IBOutlet weak var textField: UITextField!
|
18
|
+
|
19
|
+
@IBOutlet weak var sav: UIButton!
|
20
|
+
|
21
|
+
@IBOutlet weak var tln: UITextField!
|
22
|
+
|
23
|
+
@IBOutlet weak var tfn: UITextField!
|
24
|
+
|
25
|
+
@IBOutlet weak var room: UITextField!
|
26
|
+
|
27
|
+
@IBOutlet weak var tani: UITextField!
|
28
|
+
|
29
|
+
@IBOutlet weak var save: UIButton!
|
30
|
+
|
31
|
+
@IBOutlet weak var re: UITextField!
|
32
|
+
|
33
|
+
@IBOutlet weak var tyu: UITextField!
|
34
|
+
|
35
|
+
@IBOutlet weak var shu: UITextField!
|
36
|
+
|
37
|
+
@IBOutlet weak var hi: UITextField!
|
38
|
+
|
39
|
+
var targetLabel: UILabel!
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
func getTextfield(view: UIView) -> [UITextField] {
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
var results = [UITextField]()
|
48
|
+
|
49
|
+
for subview in view.subviews as [UIView] {
|
50
|
+
|
51
|
+
if let textField = subview as? UITextField {
|
52
|
+
|
53
|
+
results += [textField]
|
54
|
+
|
55
|
+
} else {
|
56
|
+
|
57
|
+
results += getTextfield(view: subview)
|
58
|
+
|
59
|
+
}
|
60
|
+
|
61
|
+
}
|
62
|
+
|
63
|
+
return results
|
64
|
+
|
65
|
+
}
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
override func viewDidLayoutSubviews() {
|
70
|
+
|
71
|
+
super.viewDidLayoutSubviews()
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
let allTextFields = getTextfield(view: self.view)
|
76
|
+
|
77
|
+
for textField in allTextFields
|
78
|
+
|
79
|
+
{
|
80
|
+
|
81
|
+
textField.font = UIFont.boldSystemFont(ofSize: 20)
|
82
|
+
|
83
|
+
var widthOfText: CGFloat = textField.text!.size(withAttributes: [NSAttributedString.Key.font: textField.font!]).width
|
84
|
+
|
85
|
+
var widthOfFrame: CGFloat = textField.frame.size.width
|
86
|
+
|
87
|
+
while (widthOfFrame - 15) < widthOfText { // try here to find the value that fits your needs
|
88
|
+
|
89
|
+
let fontSize: CGFloat = textField.font!.pointSize
|
90
|
+
|
91
|
+
textField.font = textField.font?.withSize(CGFloat(fontSize - 0.5))
|
92
|
+
|
93
|
+
widthOfText = (textField.text?.size(withAttributes: [NSAttributedString.Key.font: textField.font!]).width)!
|
94
|
+
|
95
|
+
widthOfFrame = textField.frame.size.width
|
96
|
+
|
97
|
+
}
|
98
|
+
|
99
|
+
}
|
100
|
+
|
101
|
+
}
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
override func viewDidLoad() {
|
106
|
+
|
107
|
+
super.viewDidLoad()
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
let userDefaults = UserDefaults.standard
|
112
|
+
|
113
|
+
userDefaults.string(forKey: "tlnl")
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
let defaults = UserDefaults.standard
|
118
|
+
|
119
|
+
let value = defaults.string(forKey: "tln")
|
120
|
+
|
121
|
+
tln.text = value
|
122
|
+
|
123
|
+
let valu = defaults.string(forKey: "textField")
|
124
|
+
|
125
|
+
textField.text = valu
|
126
|
+
|
127
|
+
let val = defaults.string(forKey: "tfn")
|
128
|
+
|
129
|
+
tfn.text = val
|
130
|
+
|
131
|
+
let va = defaults.string(forKey: "room")
|
132
|
+
|
133
|
+
room.text = va
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
save.layer.cornerRadius = 25
|
138
|
+
|
139
|
+
save.layer.borderWidth = 1
|
140
|
+
|
141
|
+
save.layer.borderColor = UIColor.lightGray.cgColor
|
142
|
+
|
143
|
+
|
144
|
+
|
145
|
+
self.title = self.targetLabel.text
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
let button = UIButton(frame: CGRect(x: 0, y: 0, width: 300, height: 44))
|
150
|
+
|
151
|
+
self.view.addSubview(button)
|
152
|
+
|
153
|
+
button.translatesAutoresizingMaskIntoConstraints = false
|
154
|
+
|
155
|
+
button.heightAnchor.constraint(equalToConstant: 44).isActive = true
|
156
|
+
|
157
|
+
button.widthAnchor.constraint(equalToConstant: 130).isActive = true
|
158
|
+
|
159
|
+
|
160
|
+
|
161
|
+
button.topAnchor.constraint(equalTo: tyu.bottomAnchor, constant: 20.0).isActive = true
|
162
|
+
|
163
|
+
button.trailingAnchor.constraint(equalTo: self.view.trailingAnchor, constant: -45).isActive = true
|
164
|
+
|
165
|
+
button.setTitleColor(UIColor.black, for: .normal)
|
166
|
+
|
167
|
+
button.layer.cornerRadius = 22
|
168
|
+
|
169
|
+
button.layer.borderWidth = 1
|
170
|
+
|
171
|
+
button.layer.borderColor = UIColor.lightGray.cgColor
|
172
|
+
|
173
|
+
button.setTitle("カラー選択", for: .normal)
|
174
|
+
|
175
|
+
button.center = view.center
|
176
|
+
|
177
|
+
button.addTarget(self, action: #selector(didTapSelectColor), for: .touchUpInside)
|
178
|
+
|
179
|
+
}
|
180
|
+
|
181
|
+
|
182
|
+
|
183
|
+
@objc private func didTapSelectColor() {
|
184
|
+
|
185
|
+
let colorPickerVC = UIColorPickerViewController()
|
186
|
+
|
187
|
+
colorPickerVC.delegate = self
|
188
|
+
|
189
|
+
present(colorPickerVC, animated: true)
|
190
|
+
|
191
|
+
|
192
|
+
|
193
|
+
}
|
194
|
+
|
195
|
+
|
196
|
+
|
197
|
+
func colorPickerViewControllerDidFinish(_ EditorViewController: UIColorPickerViewController) {
|
198
|
+
|
199
|
+
let color = EditorViewController.selectedColor
|
200
|
+
|
201
|
+
view.backgroundColor = color
|
202
|
+
|
203
|
+
}
|
204
|
+
|
205
|
+
|
206
|
+
|
207
|
+
@IBAction func back(_ sender: Any) {
|
208
|
+
|
209
|
+
self.view.window?.rootViewController?.dismiss(animated: true, completion: nil)
|
210
|
+
|
211
|
+
}
|
212
|
+
|
213
|
+
@IBAction func didTapApplyButton(_ sender: Any) {
|
214
|
+
|
215
|
+
|
216
|
+
|
217
|
+
let writtenText = tln.text! as String
|
218
|
+
|
219
|
+
let writtenTex = textField.text! as String
|
220
|
+
|
221
|
+
let writtenTe = tfn.text! as String
|
222
|
+
|
223
|
+
let writtenT = room.text! as String
|
224
|
+
|
225
|
+
|
226
|
+
|
227
|
+
if let tln = self.tln.text {
|
228
|
+
|
229
|
+
if let tfn = self.tfn.text {
|
230
|
+
|
231
|
+
if let room = self.room.text {
|
232
|
+
|
233
|
+
if let textField = self.textField.text {
|
234
|
+
|
235
|
+
self.targetLabel.text = textField + "\n" + tln + " " + tfn + "\n" + room
|
236
|
+
|
237
|
+
let defaults = UserDefaults.standard
|
238
|
+
|
239
|
+
defaults.set(writtenText, forKey: "tln")
|
240
|
+
|
241
|
+
defaults.set(writtenTex, forKey: "textField")
|
242
|
+
|
243
|
+
defaults.set(writtenTe, forKey: "tfn")
|
244
|
+
|
245
|
+
defaults.set(writtenT, forKey: "room")
|
246
|
+
|
247
|
+
|
248
|
+
|
249
|
+
view.endEditing(true)
|
250
|
+
|
251
|
+
}
|
252
|
+
|
253
|
+
}
|
254
|
+
|
255
|
+
}
|
256
|
+
|
257
|
+
|
258
|
+
|
259
|
+
}
|
260
|
+
|
261
|
+
|
262
|
+
|
263
|
+
|
264
|
+
|
265
|
+
|
266
|
+
|
267
|
+
self.navigationController?.popViewController(animated: true)
|
268
|
+
|
269
|
+
self.view.window?.rootViewController?.dismiss(animated: true, completion: nil)
|
270
|
+
|
271
|
+
}
|
272
|
+
|
273
|
+
}
|
274
|
+
|
275
|
+
|
276
|
+
|
1
|
-
### 前提・実現したいこと
|
277
|
+
```### 前提・実現したいこと
|
2
278
|
|
3
279
|
|
4
280
|
|