質問編集履歴
1
コードを追記しました
test
CHANGED
File without changes
|
test
CHANGED
@@ -22,11 +22,43 @@
|
|
22
22
|
|
23
23
|
|
24
24
|
|
25
|
+
class PaddingLabel: UILabel {
|
26
|
+
|
27
|
+
|
28
|
+
|
25
|
-
var padding: UIEdgeInsets = UIEdgeInsets(top: 4, left: 8, bottom: 4, right: 8)
|
29
|
+
@IBInspectable var padding: UIEdgeInsets = UIEdgeInsets(top: 4, left: 8, bottom: 4, right: 8)
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
override func drawText(in rect: CGRect) {
|
34
|
+
|
35
|
+
let newRect = UIEdgeInsetsInsetRect(rect, padding)
|
36
|
+
|
37
|
+
super.drawText(in: newRect)
|
38
|
+
|
39
|
+
}
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
override var intrinsicContentSize: CGSize {
|
44
|
+
|
45
|
+
var contentSize = super.intrinsicContentSize
|
46
|
+
|
47
|
+
contentSize.height += padding.top + padding.bottom
|
48
|
+
|
49
|
+
contentSize.width += padding.left + padding.right
|
50
|
+
|
51
|
+
return contentSize
|
52
|
+
|
53
|
+
}
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
}
|
26
58
|
|
27
59
|
|
28
60
|
|
29
|
-
let label =
|
61
|
+
let label = PaddingLabel(frame: CGRect(x:0 y: 0, width:400 , height: 100))
|
30
62
|
|
31
63
|
label.text = "長い文章・・・・・・・・"
|
32
64
|
|