回答編集履歴
4
s
test
CHANGED
@@ -34,9 +34,7 @@
|
|
34
34
|
|
35
35
|
```swift
|
36
36
|
|
37
|
-
|
38
|
-
|
39
|
-
im
|
37
|
+
import UIKit
|
40
38
|
|
41
39
|
|
42
40
|
|
3
s
test
CHANGED
@@ -23,3 +23,69 @@
|
|
23
23
|
|
24
24
|
|
25
25
|
回答追記
|
26
|
+
|
27
|
+
---
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
`AutoLayout`の制約に変えてますが参考にしてください。
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
```swift
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
im![イメージ説明](d8cef036d5fd7c66f8a8c771bf08d798.png)IKit
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
class ViewController: UIViewController {
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
@IBOutlet weak var textView: UITextView!
|
48
|
+
|
49
|
+
@IBOutlet weak var textViewHeightConstraint: NSLayoutConstraint!
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
override func viewDidLoad() {
|
54
|
+
|
55
|
+
super.viewDidLoad()
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
let height = textView.sizeThatFits(CGSize(width: textView.frame.size.width, height: CGFloat.greatestFiniteMagnitude)).height
|
60
|
+
|
61
|
+
textViewHeightConstraint.constant = height
|
62
|
+
|
63
|
+
}
|
64
|
+
|
65
|
+
}
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
extension ViewController: UITextViewDelegate {
|
72
|
+
|
73
|
+
func textViewDidChange(_ textView: UITextView) {
|
74
|
+
|
75
|
+
var frame = textView.frame
|
76
|
+
|
77
|
+
frame.size.height = textView.contentSize.height
|
78
|
+
|
79
|
+
textView.frame = frame
|
80
|
+
|
81
|
+
}
|
82
|
+
|
83
|
+
}
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
```
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
![イメージ説明](0ebf1fa152c0a949101e8cdc72276277.png)
|
2
s
test
CHANGED
@@ -19,3 +19,7 @@
|
|
19
19
|
}
|
20
20
|
|
21
21
|
```
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
回答追記
|
1
s
test
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
|
7
7
|
|
8
8
|
|
9
|
-
for i in
|
9
|
+
for i in 1...3 {
|
10
10
|
|
11
11
|
if let filePath = Bundle.main.path(forResource: String(i), ofType: "txt"),
|
12
12
|
|