@@ -123,6 +123,80 @@ final class ViewDistributionSnapshotTests: SnapshotTestCase {
123
123
)
124
124
}
125
125
126
+ @MainActor
127
+ func testHorizontalDistributionAlongBaseline( ) {
128
+ final class TestView : UIView {
129
+
130
+ // MARK: Initialization
131
+
132
+ override init ( frame: CGRect ) {
133
+ super. init ( frame: frame)
134
+
135
+ referenceView. backgroundColor = . black. withAlphaComponent ( 0.1 )
136
+ addSubview ( referenceView)
137
+
138
+ label1. font = . systemFont( ofSize: 12 )
139
+ label1. text = " Hello worldy "
140
+ label1. textColor = . black
141
+ addSubview ( label1)
142
+
143
+ label2. font = . systemFont( ofSize: 16 )
144
+ label2. text = " Hello worldy "
145
+ label2. textColor = . black
146
+ addSubview ( label2)
147
+
148
+ label3. font = . boldSystemFont( ofSize: 14 )
149
+ label3. text = " Hello worldy "
150
+ label3. textColor = . black
151
+ addSubview ( label3)
152
+
153
+ backgroundColor = . white
154
+ }
155
+
156
+ @available ( * , unavailable)
157
+ required init ? ( coder: NSCoder ) {
158
+ fatalError ( " init(coder:) has not been implemented " )
159
+ }
160
+
161
+ // MARK: Private
162
+
163
+ private let label1 : UILabel = . init( )
164
+
165
+ private let label2 : UILabel = . init( )
166
+
167
+ private let label3 : UILabel = . init( )
168
+
169
+ private let referenceView : UIView = . init( )
170
+
171
+ // MARK: UIView
172
+
173
+ override func layoutSubviews( ) {
174
+ label1. sizeToFit ( )
175
+ label2. sizeToFit ( )
176
+ label3. sizeToFit ( )
177
+
178
+ applyHorizontalSubviewDistribution (
179
+ [
180
+ label1. distributionItemUsingCapInsets,
181
+ label2. distributionItemUsingCapInsets,
182
+ label3. distributionItemUsingCapInsets,
183
+ ] ,
184
+ inRect: bounds. insetBy ( bottom: 8 ) ,
185
+ orthogonalAlignment: . bottom( inset: 0 )
186
+ )
187
+
188
+ referenceView. untransformedFrame = bounds. slice ( from: . maxYEdge, amount: 8 ) . slice
189
+ }
190
+
191
+ }
192
+
193
+ assertSnapshot (
194
+ matching: TestView ( frame: . init( x: 0 , y: 0 , width: 400 , height: 64 ) ) ,
195
+ as: . image,
196
+ named: nameForSnapshot ( with: [ ] )
197
+ )
198
+ }
199
+
126
200
}
127
201
128
202
// MARK: -
0 commit comments