@@ -6,13 +6,18 @@ import UIKit
6
6
import Warp
7
7
8
8
public class HorizontalIconCollectionViewCell : UICollectionViewCell {
9
- private static let titleSideMargin = Warp . Spacing. spacing100
9
+ private static let leadingInset : CGFloat = 0
10
+ private static let trailingInset : CGFloat = Warp . Spacing. spacing100
11
+ private static let iconToTextSpacing : CGFloat = Warp . Spacing. spacing100
12
+ private static let verticalPadding : CGFloat = Warp . Spacing. spacing50
10
13
private static let titleStyle = Warp . Typography. body
11
14
private static let bodyStyle = Warp . Typography. bodyStrong
12
15
13
16
static func height( for viewModel: IconCollectionViewModel , withWidth width: CGFloat ) -> CGFloat {
14
17
let imageSize = viewModel. image. size
15
- let textWidth = width - imageSize. width - ( 3 * titleSideMargin)
18
+ let textWidth = width
19
+ - imageSize. width
20
+ - ( Self . leadingInset + Self. iconToTextSpacing + Self. trailingInset)
16
21
17
22
let titleHeight = viewModel. title? . height ( withConstrainedWidth: textWidth, font: titleStyle. uiFont) ?? 0
18
23
let bodyHeight = viewModel. text. height ( withConstrainedWidth: textWidth, font: bodyStyle. uiFont)
@@ -87,15 +92,17 @@ public class HorizontalIconCollectionViewCell: UICollectionViewCell {
87
92
88
93
NSLayoutConstraint . activate ( [
89
94
iconImageView. centerYAnchor. constraint ( equalTo: contentView. centerYAnchor) ,
90
- iconImageView. leadingAnchor. constraint ( equalTo: contentView. leadingAnchor, constant: HorizontalIconCollectionViewCell . titleSideMargin ) ,
95
+ iconImageView. leadingAnchor. constraint ( equalTo: contentView. leadingAnchor, constant: Self . leadingInset ) ,
91
96
92
- titleLabel. topAnchor. constraint ( equalTo: contentView. topAnchor, constant: Warp . Spacing . spacing50 ) ,
93
- titleLabel. leadingAnchor. constraint ( equalTo: iconImageView. trailingAnchor, constant: HorizontalIconCollectionViewCell . titleSideMargin ) ,
94
- titleLabel. trailingAnchor. constraint ( equalTo: contentView. trailingAnchor, constant: - HorizontalIconCollectionViewCell . titleSideMargin ) ,
97
+ titleLabel. topAnchor. constraint ( equalTo: contentView. topAnchor, constant: Self . verticalPadding ) ,
98
+ titleLabel. leadingAnchor. constraint ( equalTo: iconImageView. trailingAnchor, constant: Self . iconToTextSpacing ) ,
99
+ titleLabel. trailingAnchor. constraint ( equalTo: contentView. trailingAnchor, constant: - Self . trailingInset ) ,
95
100
96
101
bodyLabel. topAnchor. constraint ( equalTo: titleLabel. bottomAnchor) ,
97
- bodyLabel. leadingAnchor. constraint ( equalTo: iconImageView. trailingAnchor, constant: HorizontalIconCollectionViewCell . titleSideMargin) ,
98
- bodyLabel. trailingAnchor. constraint ( equalTo: contentView. trailingAnchor, constant: - HorizontalIconCollectionViewCell. titleSideMargin)
102
+ bodyLabel. leadingAnchor. constraint ( equalTo: iconImageView. trailingAnchor, constant: Self . iconToTextSpacing) ,
103
+ bodyLabel. trailingAnchor. constraint ( equalTo: contentView. trailingAnchor, constant: - Self. trailingInset) ,
104
+
105
+ bodyLabel. bottomAnchor. constraint ( lessThanOrEqualTo: contentView. bottomAnchor, constant: - Self. verticalPadding)
99
106
] )
100
107
}
101
108
}
0 commit comments