質問編集履歴
1
コードを追記しました
title
CHANGED
File without changes
|
body
CHANGED
@@ -10,9 +10,25 @@
|
|
10
10
|
|
11
11
|
```Swift
|
12
12
|
|
13
|
+
class PaddingLabel: UILabel {
|
14
|
+
|
13
|
-
var padding: UIEdgeInsets = UIEdgeInsets(top: 4, left: 8, bottom: 4, right: 8)
|
15
|
+
@IBInspectable var padding: UIEdgeInsets = UIEdgeInsets(top: 4, left: 8, bottom: 4, right: 8)
|
16
|
+
|
17
|
+
override func drawText(in rect: CGRect) {
|
18
|
+
let newRect = UIEdgeInsetsInsetRect(rect, padding)
|
19
|
+
super.drawText(in: newRect)
|
20
|
+
}
|
21
|
+
|
22
|
+
override var intrinsicContentSize: CGSize {
|
23
|
+
var contentSize = super.intrinsicContentSize
|
24
|
+
contentSize.height += padding.top + padding.bottom
|
25
|
+
contentSize.width += padding.left + padding.right
|
26
|
+
return contentSize
|
27
|
+
}
|
28
|
+
|
29
|
+
}
|
14
30
|
|
15
|
-
let label =
|
31
|
+
let label = PaddingLabel(frame: CGRect(x:0 y: 0, width:400 , height: 100))
|
16
32
|
label.text = "長い文章・・・・・・・・"
|
17
33
|
label.sizeToFit()
|
18
34
|
// 正しく表示できない
|