@@ -10,10 +10,10 @@ extension UIButton {
1010 func applyPrimaryButtonStyle( ) {
1111 var configuration = UIButton . Configuration. filled ( )
1212 configuration. contentInsets = . init(
13- top: Style . defaultInsets . top ,
14- leading: Style . defaultInsets . leading ,
15- bottom: Style . defaultInsets . bottom ,
16- trailing: Style . defaultInsets . trailing
13+ top: Style . defaultVerticalInsets ,
14+ leading: Style . defaultHorizontalInsets ,
15+ bottom: Style . defaultVerticalInsets ,
16+ trailing: Style . defaultHorizontalInsets
1717 )
1818 layer. borderColor = UIColor . primaryButtonBorder. cgColor
1919 layer. borderWidth = Style . defaultBorderWidth
@@ -47,10 +47,10 @@ extension UIButton {
4747 func applySecondaryButtonStyle( ) {
4848 var configuration = UIButton . Configuration. filled ( )
4949 configuration. contentInsets = . init(
50- top: Style . defaultInsets . top ,
51- leading: Style . defaultInsets . leading ,
52- bottom: Style . defaultInsets . bottom ,
53- trailing: Style . defaultInsets . trailing
50+ top: Style . defaultVerticalInsets ,
51+ leading: Style . defaultHorizontalInsets ,
52+ bottom: Style . defaultVerticalInsets ,
53+ trailing: Style . defaultHorizontalInsets
5454 )
5555 backgroundColor = . secondaryButtonBackground
5656 layer. borderColor = UIColor . secondaryButtonBorder. cgColor
@@ -85,10 +85,10 @@ extension UIButton {
8585 func applyLinkButtonStyle( enableMultipleLines: Bool = false ) {
8686 var configuration = UIButton . Configuration. plain ( )
8787 configuration. contentInsets = . init(
88- top: Style . defaultInsets . top ,
89- leading: Style . defaultInsets . leading ,
90- bottom: Style . defaultInsets . bottom ,
91- trailing: Style . defaultInsets . trailing
88+ top: Style . defaultVerticalInsets ,
89+ leading: Style . defaultHorizontalInsets ,
90+ bottom: Style . defaultVerticalInsets ,
91+ trailing: Style . defaultHorizontalInsets
9292 )
9393 backgroundColor = . clear
9494 tintColor = . accent
@@ -113,8 +113,13 @@ extension UIButton {
113113 }
114114
115115 func applyPaymentsModalCancelButtonStyle( ) {
116- configuration = UIButton . Configuration. plain ( )
117- configuration? . contentInsets = Style . defaultInsets
116+ var configuration = UIButton . Configuration. plain ( )
117+ configuration. contentInsets = . init(
118+ top: Style . defaultVerticalInsets,
119+ leading: Style . defaultHorizontalInsets,
120+ bottom: Style . defaultVerticalInsets,
121+ trailing: Style . defaultHorizontalInsets
122+ )
118123 backgroundColor = . tertiarySystemBackground
119124 layer. borderColor = UIColor . secondaryButtonBorder. cgColor
120125 layer. borderWidth = Style . defaultBorderWidth
@@ -166,8 +171,16 @@ extension UIButton {
166171 private func enableMultipleLines( ) {
167172 titleLabel? . lineBreakMode = . byWordWrapping
168173 if let label = titleLabel {
169- self . addSubview ( label)
170- pinSubviewToAllEdgeMargins ( label)
174+ if self . subviews. contains ( where: { $0 == label } ) {
175+ pinSubviewToAllEdgeMargins ( label)
176+ } else {
177+ DDLogWarn ( """
178+ Failed attempt to pin button's title to the edges.
179+ This is likely because the custom button title label was not added to its view hierarchy
180+ See ButtonActivityIndicator as an example
181+ """
182+ )
183+ }
171184 }
172185 }
173186}
@@ -180,6 +193,7 @@ private extension UIButton {
180193 struct Style {
181194 static let defaultCornerRadius = CGFloat ( 8.0 )
182195 static let defaultBorderWidth = CGFloat ( 1.0 )
183- static let defaultEdgeInsets = UIEdgeInsets ( top: 12 , left: 22 , bottom: 12 , right: 22 )
196+ static let defaultVerticalInsets = CGFloat ( 12 )
197+ static let defaultHorizontalInsets = CGFloat ( 22 )
184198 }
185199}
0 commit comments