9
9
import UIKit
10
10
import AttributedStringWrapper
11
11
12
+ let screenW = UIScreen . main. bounds. width
13
+
14
+
12
15
class ViewController : UIViewController {
13
16
14
17
@IBOutlet weak var label1 : UILabel !
@@ -25,19 +28,25 @@ class ViewController: UIViewController {
25
28
26
29
27
30
// 1. shadow: you can set range, default allRange
28
- label1 . attributedText = content. toAttributed. shadow {
31
+ let attrText1 = content. toAttributed. shadow {
29
32
$0. shadowColor = UIColor . red
30
33
$0. shadowOffset = CGSize ( width: 3 , height: 3 )
31
34
$0. shadowBlurRadius = 2.0
32
- } . rawValue
35
+ } . font ( UIFont . systemFont ( ofSize: 15 ) )
36
+
37
+ label1. attributedText = attrText1. rawValue
38
+ // Add the shadow offset
39
+ print ( attrText1. getHeight ( by: screenW - 20 ) + 3 )
33
40
34
41
35
42
36
43
// 2. paragraphStyle: you can set range, default allRange
37
- label2 . attributedText = content. toAttributed. paragraph {
44
+ let attrText2 = content. toAttributed. paragraph {
38
45
$0. alignment = . center
39
46
$0. lineSpacing = 8.0
40
- } . rawValue
47
+ } . font ( UIFont . systemFont ( ofSize: 15 ) )
48
+ label2. attributedText = attrText2. rawValue
49
+ print ( attrText2. getHeight ( by: screenW - 20 ) )
41
50
42
51
43
52
@@ -54,8 +63,6 @@ class ViewController: UIViewController {
54
63
// 5. strokeStyle:
55
64
label5. attributedText = content. toAttributed. stroke ( color: UIColor . blue, width: 2.5 ) . rawValue
56
65
57
-
58
-
59
66
// 6. all:
60
67
label6. attributedText = content. toAttributed
61
68
. underLine ( style: [ . styleSingle, . patternDot] , color: . red, range: NSMakeRange ( 0 , 5 ) )
@@ -74,5 +81,16 @@ class ViewController: UIViewController {
74
81
$0. shadowBlurRadius = 2.0
75
82
} . rawValue
76
83
}
84
+
85
+ override func viewDidLayoutSubviews( ) {
86
+ super. viewDidLayoutSubviews ( )
87
+ print ( " label1 height: \( label1. frame. height) " )
88
+ print ( " label2 height: \( label2. frame. height) " )
89
+ }
90
+
77
91
}
78
92
93
+
94
+
95
+
96
+
0 commit comments