From 4f2f0489cbdb340f6f47f5076f8da7b529ed3922 Mon Sep 17 00:00:00 2001 From: iamgabrielma Date: Fri, 11 Nov 2022 13:05:52 +0900 Subject: [PATCH 01/21] Use UIButton.Configuration on CustomerNote cell --- .../Customer Section/CustomerNoteTableViewCell.swift | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/WooCommerce/Classes/ViewRelated/Orders/Order Details/Customer Section/CustomerNoteTableViewCell.swift b/WooCommerce/Classes/ViewRelated/Orders/Order Details/Customer Section/CustomerNoteTableViewCell.swift index 9b8d31df1f5..087460cd9e7 100644 --- a/WooCommerce/Classes/ViewRelated/Orders/Order Details/Customer Section/CustomerNoteTableViewCell.swift +++ b/WooCommerce/Classes/ViewRelated/Orders/Order Details/Customer Section/CustomerNoteTableViewCell.swift @@ -128,7 +128,14 @@ private extension CustomerNoteTableViewCell { addButton.setImage(.plusImage, for: .normal) addButton.contentHorizontalAlignment = .leading addButton.contentVerticalAlignment = .bottom - addButton.contentEdgeInsets = .zero + // Usage of Configuration.contentInsets: + addButton.configuration = UIButton.Configuration.plain() + addButton.configuration?.contentInsets = .zero + // Testing: Remove before submitting for review + addButton.backgroundColor = .yellow + addButton.layer.borderColor = CGColor(red: 1, green: 0, blue: 0, alpha: 1) + addButton.layer.borderWidth = 2.0 + // addButton.distributeTitleAndImage(spacing: Constants.buttonTitleAndImageSpacing) addButton.addTarget(self, action: #selector(addButtonTapped), for: .touchUpInside) } From 2e3a9e84fcc9a8a05f095649ace538c30347e193 Mon Sep 17 00:00:00 2001 From: iamgabrielma Date: Fri, 11 Nov 2022 13:27:27 +0900 Subject: [PATCH 02/21] Update applyLinkButtonStyle() with UIButton.Configuration --- WooCommerce/Classes/Extensions/UIButton+Helpers.swift | 4 +++- .../Customer Section/CustomerNoteTableViewCell.swift | 2 -- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/WooCommerce/Classes/Extensions/UIButton+Helpers.swift b/WooCommerce/Classes/Extensions/UIButton+Helpers.swift index c8118559489..7914ebf97e9 100644 --- a/WooCommerce/Classes/Extensions/UIButton+Helpers.swift +++ b/WooCommerce/Classes/Extensions/UIButton+Helpers.swift @@ -71,8 +71,9 @@ extension UIButton { /// Applies the Link Button Style: Clear BG / Brand Text Color /// func applyLinkButtonStyle(enableMultipleLines: Bool = false) { + configuration = UIButton.Configuration.plain() backgroundColor = .clear - contentEdgeInsets = Style.defaultEdgeInsets + configuration?.contentInsets = Style.defaultInsets tintColor = .accent titleLabel?.applyBodyStyle() titleLabel?.textAlignment = .natural @@ -161,5 +162,6 @@ private extension UIButton { static let defaultCornerRadius = CGFloat(8.0) static let defaultBorderWidth = CGFloat(1.0) static let defaultEdgeInsets = UIEdgeInsets(top: 12, left: 22, bottom: 12, right: 22) + static let defaultInsets = NSDirectionalEdgeInsets(top: 12, leading: 22, bottom: 12, trailing: 22) } } diff --git a/WooCommerce/Classes/ViewRelated/Orders/Order Details/Customer Section/CustomerNoteTableViewCell.swift b/WooCommerce/Classes/ViewRelated/Orders/Order Details/Customer Section/CustomerNoteTableViewCell.swift index 087460cd9e7..64c7c9aaa8a 100644 --- a/WooCommerce/Classes/ViewRelated/Orders/Order Details/Customer Section/CustomerNoteTableViewCell.swift +++ b/WooCommerce/Classes/ViewRelated/Orders/Order Details/Customer Section/CustomerNoteTableViewCell.swift @@ -128,8 +128,6 @@ private extension CustomerNoteTableViewCell { addButton.setImage(.plusImage, for: .normal) addButton.contentHorizontalAlignment = .leading addButton.contentVerticalAlignment = .bottom - // Usage of Configuration.contentInsets: - addButton.configuration = UIButton.Configuration.plain() addButton.configuration?.contentInsets = .zero // Testing: Remove before submitting for review addButton.backgroundColor = .yellow From 13ebacdbad5c5e8c3428fe122071fc490d719c48 Mon Sep 17 00:00:00 2001 From: iamgabrielma Date: Fri, 11 Nov 2022 13:28:07 +0900 Subject: [PATCH 03/21] Update edgeInsets SurveySubmittedViewController --- .../ViewRelated/Survey/SurveySubmittedViewController.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WooCommerce/Classes/ViewRelated/Survey/SurveySubmittedViewController.swift b/WooCommerce/Classes/ViewRelated/Survey/SurveySubmittedViewController.swift index 80288f88d6d..794672c0be2 100644 --- a/WooCommerce/Classes/ViewRelated/Survey/SurveySubmittedViewController.swift +++ b/WooCommerce/Classes/ViewRelated/Survey/SurveySubmittedViewController.swift @@ -93,7 +93,7 @@ private extension SurveySubmittedViewController { contactUsButton.applyLinkButtonStyle() contactUsButton.titleLabel?.applyCalloutStyle() - contactUsButton.contentEdgeInsets = .zero + contactUsButton.configuration?.contentInsets = .zero } /// Apply the correspondent localized texts to each component From f5f359b54998aa55fd2b16b4a16038a8a9127e39 Mon Sep 17 00:00:00 2001 From: iamgabrielma Date: Fri, 11 Nov 2022 13:48:12 +0900 Subject: [PATCH 04/21] Update edgeInsets applySecondaryButtonStyle --- WooCommerce/Classes/Extensions/UIButton+Helpers.swift | 6 ++++-- .../Payment Section/Refunds/IssueRefundTableViewCell.swift | 5 +++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/WooCommerce/Classes/Extensions/UIButton+Helpers.swift b/WooCommerce/Classes/Extensions/UIButton+Helpers.swift index 7914ebf97e9..254921c21a9 100644 --- a/WooCommerce/Classes/Extensions/UIButton+Helpers.swift +++ b/WooCommerce/Classes/Extensions/UIButton+Helpers.swift @@ -39,13 +39,15 @@ extension UIButton { /// Applies the Secondary Button Style: Clear BG / Bordered Outline /// func applySecondaryButtonStyle() { + configuration = UIButton.Configuration.plain() backgroundColor = .secondaryButtonBackground - contentEdgeInsets = Style.defaultEdgeInsets + configuration?.contentInsets = Style.defaultInsets layer.borderColor = UIColor.secondaryButtonBorder.cgColor layer.borderWidth = Style.defaultBorderWidth layer.cornerRadius = Style.defaultCornerRadius titleLabel?.applyHeadlineStyle() - enableMultipleLines() + // If we call enableMultipleLines(), now crashes. + //enableMultipleLines() titleLabel?.textAlignment = .center setTitleColor(.secondaryButtonTitle, for: .normal) diff --git a/WooCommerce/Classes/ViewRelated/Orders/Order Details/Payment Section/Refunds/IssueRefundTableViewCell.swift b/WooCommerce/Classes/ViewRelated/Orders/Order Details/Payment Section/Refunds/IssueRefundTableViewCell.swift index adb00582b38..ed204bb2cbe 100644 --- a/WooCommerce/Classes/ViewRelated/Orders/Order Details/Payment Section/Refunds/IssueRefundTableViewCell.swift +++ b/WooCommerce/Classes/ViewRelated/Orders/Order Details/Payment Section/Refunds/IssueRefundTableViewCell.swift @@ -30,6 +30,11 @@ private extension IssueRefundTableViewCell { func configureIssueRefundButton() { issueRefundButton.applySecondaryButtonStyle() + // Testing: Remove before submitting for review + issueRefundButton.backgroundColor = .yellow + issueRefundButton.layer.borderColor = CGColor(red: 1, green: 0, blue: 0, alpha: 1) + issueRefundButton.layer.borderWidth = 2.0 + // issueRefundButton.setTitle(Localization.buttonTitle, for: .normal) } } From 4a66349e22e9334e0901988a2c51ae4bb5759901 Mon Sep 17 00:00:00 2001 From: iamgabrielma Date: Fri, 11 Nov 2022 14:03:13 +0900 Subject: [PATCH 05/21] Update paymentsModalCancelButtonStyle edgeInsets --- WooCommerce/Classes/Extensions/UIButton+Helpers.swift | 9 +++++---- .../CardPresentPaymentsModalViewController.swift | 5 +++++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/WooCommerce/Classes/Extensions/UIButton+Helpers.swift b/WooCommerce/Classes/Extensions/UIButton+Helpers.swift index 254921c21a9..f35c8a1f9e1 100644 --- a/WooCommerce/Classes/Extensions/UIButton+Helpers.swift +++ b/WooCommerce/Classes/Extensions/UIButton+Helpers.swift @@ -40,8 +40,8 @@ extension UIButton { /// func applySecondaryButtonStyle() { configuration = UIButton.Configuration.plain() - backgroundColor = .secondaryButtonBackground configuration?.contentInsets = Style.defaultInsets + backgroundColor = .secondaryButtonBackground layer.borderColor = UIColor.secondaryButtonBorder.cgColor layer.borderWidth = Style.defaultBorderWidth layer.cornerRadius = Style.defaultCornerRadius @@ -74,8 +74,8 @@ extension UIButton { /// func applyLinkButtonStyle(enableMultipleLines: Bool = false) { configuration = UIButton.Configuration.plain() - backgroundColor = .clear configuration?.contentInsets = Style.defaultInsets + backgroundColor = .clear tintColor = .accent titleLabel?.applyBodyStyle() titleLabel?.textAlignment = .natural @@ -98,13 +98,14 @@ extension UIButton { } func applyPaymentsModalCancelButtonStyle() { + configuration = UIButton.Configuration.plain() + configuration?.contentInsets = Style.defaultInsets backgroundColor = .tertiarySystemBackground - contentEdgeInsets = Style.defaultEdgeInsets layer.borderColor = UIColor.secondaryButtonBorder.cgColor layer.borderWidth = Style.defaultBorderWidth layer.cornerRadius = Style.defaultCornerRadius titleLabel?.applyHeadlineStyle() - enableMultipleLines() + //enableMultipleLines() titleLabel?.textAlignment = .center setTitleColor(.secondaryButtonTitle, for: .normal) diff --git a/WooCommerce/Classes/ViewRelated/CardPresentPayments/CardPresentPaymentsModalViewController.swift b/WooCommerce/Classes/ViewRelated/CardPresentPayments/CardPresentPaymentsModalViewController.swift index 41a4f1a85dd..c673610d831 100644 --- a/WooCommerce/Classes/ViewRelated/CardPresentPayments/CardPresentPaymentsModalViewController.swift +++ b/WooCommerce/Classes/ViewRelated/CardPresentPayments/CardPresentPaymentsModalViewController.swift @@ -153,6 +153,11 @@ private extension CardPresentPaymentsModalViewController { func styleSecondaryButton() { secondaryButton.applyPaymentsModalCancelButtonStyle() + // Testing: Remove before submitting for review + secondaryButton.backgroundColor = .yellow + secondaryButton.layer.borderColor = CGColor(red: 1, green: 0, blue: 0, alpha: 1) + secondaryButton.layer.borderWidth = 2.0 + // secondaryButton.titleLabel?.adjustsFontSizeToFitWidth = true secondaryButton.titleLabel?.minimumScaleFactor = 0.5 } From 36356049dbb28fb5e6ee0ba2d08dfe7ff4618a6f Mon Sep 17 00:00:00 2001 From: iamgabrielma Date: Fri, 11 Nov 2022 14:48:45 +0900 Subject: [PATCH 06/21] Comment-out calls to pinSubviewToAllEdgeMargins MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit By using UIButton.Configuration, calls to pinSubviewToAllEdgeMargins() make the app crash, as is illegal to activate constraints with anchors in different view hierarchies. By commenting this out temporarily, while buttons doesn’t look great if they have multiple lines, we avoid the app crash. --- .../Classes/Extensions/UIButton+Helpers.swift | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/WooCommerce/Classes/Extensions/UIButton+Helpers.swift b/WooCommerce/Classes/Extensions/UIButton+Helpers.swift index f35c8a1f9e1..6943d32b575 100644 --- a/WooCommerce/Classes/Extensions/UIButton+Helpers.swift +++ b/WooCommerce/Classes/Extensions/UIButton+Helpers.swift @@ -46,8 +46,7 @@ extension UIButton { layer.borderWidth = Style.defaultBorderWidth layer.cornerRadius = Style.defaultCornerRadius titleLabel?.applyHeadlineStyle() - // If we call enableMultipleLines(), now crashes. - //enableMultipleLines() + enableMultipleLines() titleLabel?.textAlignment = .center setTitleColor(.secondaryButtonTitle, for: .normal) @@ -105,7 +104,7 @@ extension UIButton { layer.borderWidth = Style.defaultBorderWidth layer.cornerRadius = Style.defaultCornerRadius titleLabel?.applyHeadlineStyle() - //enableMultipleLines() + enableMultipleLines() titleLabel?.textAlignment = .center setTitleColor(.secondaryButtonTitle, for: .normal) @@ -150,9 +149,10 @@ extension UIButton { /// Supports title of multiple lines, either from longer text than allocated width or text with line breaks. private func enableMultipleLines() { titleLabel?.lineBreakMode = .byWordWrapping - if let label = titleLabel { - pinSubviewToAllEdgeMargins(label) - } +// This bit makes the app crash now that we use UIButton.Configuration +// if let label = titleLabel { +// pinSubviewToAllEdgeMargins(label) +// } } } From 3fb5e8f49c6de83b3091d2c5ce99a30f66e7adda Mon Sep 17 00:00:00 2001 From: iamgabrielma Date: Tue, 15 Nov 2022 14:33:22 +0900 Subject: [PATCH 07/21] Use Button Configuration on applying button style --- .../Classes/Extensions/UIButton+Helpers.swift | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/WooCommerce/Classes/Extensions/UIButton+Helpers.swift b/WooCommerce/Classes/Extensions/UIButton+Helpers.swift index 6943d32b575..c39ed3f492d 100644 --- a/WooCommerce/Classes/Extensions/UIButton+Helpers.swift +++ b/WooCommerce/Classes/Extensions/UIButton+Helpers.swift @@ -8,7 +8,13 @@ extension UIButton { /// Applies the Primary Button Style: Solid BG! /// func applyPrimaryButtonStyle() { - contentEdgeInsets = Style.defaultEdgeInsets + var configuration = UIButton.Configuration.filled() + configuration.contentInsets = .init( + top: Style.defaultInsets.top, + leading: Style.defaultInsets.leading, + bottom: Style.defaultInsets.bottom, + trailing: Style.defaultInsets.trailing + ) layer.borderColor = UIColor.primaryButtonBorder.cgColor layer.borderWidth = Style.defaultBorderWidth layer.cornerRadius = Style.defaultCornerRadius @@ -39,8 +45,13 @@ extension UIButton { /// Applies the Secondary Button Style: Clear BG / Bordered Outline /// func applySecondaryButtonStyle() { - configuration = UIButton.Configuration.plain() - configuration?.contentInsets = Style.defaultInsets + var configuration = UIButton.Configuration.filled() + configuration.contentInsets = .init( + top: Style.defaultInsets.top, + leading: Style.defaultInsets.leading, + bottom: Style.defaultInsets.bottom, + trailing: Style.defaultInsets.trailing + ) backgroundColor = .secondaryButtonBackground layer.borderColor = UIColor.secondaryButtonBorder.cgColor layer.borderWidth = Style.defaultBorderWidth From 84eba80092808b29b0f0353bc8602f3b55c1acca Mon Sep 17 00:00:00 2001 From: iamgabrielma Date: Tue, 15 Nov 2022 14:34:54 +0900 Subject: [PATCH 08/21] Revert testing button backgrounds --- .../CardPresentPaymentsModalViewController.swift | 5 ----- .../Customer Section/CustomerNoteTableViewCell.swift | 5 ----- .../Payment Section/Refunds/IssueRefundTableViewCell.swift | 5 ----- 3 files changed, 15 deletions(-) diff --git a/WooCommerce/Classes/ViewRelated/CardPresentPayments/CardPresentPaymentsModalViewController.swift b/WooCommerce/Classes/ViewRelated/CardPresentPayments/CardPresentPaymentsModalViewController.swift index c673610d831..41a4f1a85dd 100644 --- a/WooCommerce/Classes/ViewRelated/CardPresentPayments/CardPresentPaymentsModalViewController.swift +++ b/WooCommerce/Classes/ViewRelated/CardPresentPayments/CardPresentPaymentsModalViewController.swift @@ -153,11 +153,6 @@ private extension CardPresentPaymentsModalViewController { func styleSecondaryButton() { secondaryButton.applyPaymentsModalCancelButtonStyle() - // Testing: Remove before submitting for review - secondaryButton.backgroundColor = .yellow - secondaryButton.layer.borderColor = CGColor(red: 1, green: 0, blue: 0, alpha: 1) - secondaryButton.layer.borderWidth = 2.0 - // secondaryButton.titleLabel?.adjustsFontSizeToFitWidth = true secondaryButton.titleLabel?.minimumScaleFactor = 0.5 } diff --git a/WooCommerce/Classes/ViewRelated/Orders/Order Details/Customer Section/CustomerNoteTableViewCell.swift b/WooCommerce/Classes/ViewRelated/Orders/Order Details/Customer Section/CustomerNoteTableViewCell.swift index 64c7c9aaa8a..0b792c54748 100644 --- a/WooCommerce/Classes/ViewRelated/Orders/Order Details/Customer Section/CustomerNoteTableViewCell.swift +++ b/WooCommerce/Classes/ViewRelated/Orders/Order Details/Customer Section/CustomerNoteTableViewCell.swift @@ -129,11 +129,6 @@ private extension CustomerNoteTableViewCell { addButton.contentHorizontalAlignment = .leading addButton.contentVerticalAlignment = .bottom addButton.configuration?.contentInsets = .zero - // Testing: Remove before submitting for review - addButton.backgroundColor = .yellow - addButton.layer.borderColor = CGColor(red: 1, green: 0, blue: 0, alpha: 1) - addButton.layer.borderWidth = 2.0 - // addButton.distributeTitleAndImage(spacing: Constants.buttonTitleAndImageSpacing) addButton.addTarget(self, action: #selector(addButtonTapped), for: .touchUpInside) } diff --git a/WooCommerce/Classes/ViewRelated/Orders/Order Details/Payment Section/Refunds/IssueRefundTableViewCell.swift b/WooCommerce/Classes/ViewRelated/Orders/Order Details/Payment Section/Refunds/IssueRefundTableViewCell.swift index ed204bb2cbe..adb00582b38 100644 --- a/WooCommerce/Classes/ViewRelated/Orders/Order Details/Payment Section/Refunds/IssueRefundTableViewCell.swift +++ b/WooCommerce/Classes/ViewRelated/Orders/Order Details/Payment Section/Refunds/IssueRefundTableViewCell.swift @@ -30,11 +30,6 @@ private extension IssueRefundTableViewCell { func configureIssueRefundButton() { issueRefundButton.applySecondaryButtonStyle() - // Testing: Remove before submitting for review - issueRefundButton.backgroundColor = .yellow - issueRefundButton.layer.borderColor = CGColor(red: 1, green: 0, blue: 0, alpha: 1) - issueRefundButton.layer.borderWidth = 2.0 - // issueRefundButton.setTitle(Localization.buttonTitle, for: .normal) } } From 5450244137f057e013f0711cae7953a8391fe6dc Mon Sep 17 00:00:00 2001 From: iamgabrielma Date: Tue, 15 Nov 2022 14:47:36 +0900 Subject: [PATCH 09/21] Add Configuration to applyLinkButtonStyle --- .../Classes/Extensions/UIButton+Helpers.swift | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/WooCommerce/Classes/Extensions/UIButton+Helpers.swift b/WooCommerce/Classes/Extensions/UIButton+Helpers.swift index c39ed3f492d..5573388ecbf 100644 --- a/WooCommerce/Classes/Extensions/UIButton+Helpers.swift +++ b/WooCommerce/Classes/Extensions/UIButton+Helpers.swift @@ -83,8 +83,13 @@ extension UIButton { /// Applies the Link Button Style: Clear BG / Brand Text Color /// func applyLinkButtonStyle(enableMultipleLines: Bool = false) { - configuration = UIButton.Configuration.plain() - configuration?.contentInsets = Style.defaultInsets + var configuration = UIButton.Configuration.filled() + configuration.contentInsets = .init( + top: Style.defaultInsets.top, + leading: Style.defaultInsets.leading, + bottom: Style.defaultInsets.bottom, + trailing: Style.defaultInsets.trailing + ) backgroundColor = .clear tintColor = .accent titleLabel?.applyBodyStyle() @@ -160,10 +165,9 @@ extension UIButton { /// Supports title of multiple lines, either from longer text than allocated width or text with line breaks. private func enableMultipleLines() { titleLabel?.lineBreakMode = .byWordWrapping -// This bit makes the app crash now that we use UIButton.Configuration -// if let label = titleLabel { -// pinSubviewToAllEdgeMargins(label) -// } + if let label = titleLabel { + pinSubviewToAllEdgeMargins(label) + } } } From 028beb1fa3e25aa556dc33bf83ad5ff6954b08bd Mon Sep 17 00:00:00 2001 From: iamgabrielma Date: Tue, 15 Nov 2022 14:49:59 +0900 Subject: [PATCH 10/21] revert testing button configuration --- .../Customer Section/CustomerNoteTableViewCell.swift | 2 +- .../ViewRelated/Survey/SurveySubmittedViewController.swift | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/WooCommerce/Classes/ViewRelated/Orders/Order Details/Customer Section/CustomerNoteTableViewCell.swift b/WooCommerce/Classes/ViewRelated/Orders/Order Details/Customer Section/CustomerNoteTableViewCell.swift index 0b792c54748..9b8d31df1f5 100644 --- a/WooCommerce/Classes/ViewRelated/Orders/Order Details/Customer Section/CustomerNoteTableViewCell.swift +++ b/WooCommerce/Classes/ViewRelated/Orders/Order Details/Customer Section/CustomerNoteTableViewCell.swift @@ -128,7 +128,7 @@ private extension CustomerNoteTableViewCell { addButton.setImage(.plusImage, for: .normal) addButton.contentHorizontalAlignment = .leading addButton.contentVerticalAlignment = .bottom - addButton.configuration?.contentInsets = .zero + addButton.contentEdgeInsets = .zero addButton.distributeTitleAndImage(spacing: Constants.buttonTitleAndImageSpacing) addButton.addTarget(self, action: #selector(addButtonTapped), for: .touchUpInside) } diff --git a/WooCommerce/Classes/ViewRelated/Survey/SurveySubmittedViewController.swift b/WooCommerce/Classes/ViewRelated/Survey/SurveySubmittedViewController.swift index 794672c0be2..80288f88d6d 100644 --- a/WooCommerce/Classes/ViewRelated/Survey/SurveySubmittedViewController.swift +++ b/WooCommerce/Classes/ViewRelated/Survey/SurveySubmittedViewController.swift @@ -93,7 +93,7 @@ private extension SurveySubmittedViewController { contactUsButton.applyLinkButtonStyle() contactUsButton.titleLabel?.applyCalloutStyle() - contactUsButton.configuration?.contentInsets = .zero + contactUsButton.contentEdgeInsets = .zero } /// Apply the correspondent localized texts to each component From fa02ba8282deaf676f00a6587d5cb80db484a17a Mon Sep 17 00:00:00 2001 From: iamgabrielma Date: Tue, 15 Nov 2022 15:08:15 +0900 Subject: [PATCH 11/21] Add Button Configuration to VerticalButton --- .../ReusableViews/VerticalButton.swift | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/WooCommerce/Classes/ViewRelated/ReusableViews/VerticalButton.swift b/WooCommerce/Classes/ViewRelated/ReusableViews/VerticalButton.swift index d6b692c5ede..6467d55923c 100644 --- a/WooCommerce/Classes/ViewRelated/ReusableViews/VerticalButton.swift +++ b/WooCommerce/Classes/ViewRelated/ReusableViews/VerticalButton.swift @@ -10,10 +10,7 @@ class VerticalButton: UIButton { override func awakeFromNib() { super.awakeFromNib() - - contentEdgeInsets = Settings.edgeInsets - layer.cornerRadius = Settings.cornerRadius - titleLabel?.font = UIFont.footnote + configureButton() } override func layoutSubviews() { @@ -42,6 +39,18 @@ class VerticalButton: UIButton { width: titleSize.width, height: titleSize.height).integral } + + private func configureButton() { + var configuration = UIButton.Configuration.filled() + configuration.contentInsets = .init( + top: .zero, + leading: Settings.horizontalEdgeInsets, + bottom: .zero, + trailing: Settings.horizontalEdgeInsets + ) + layer.cornerRadius = Settings.cornerRadius + titleLabel?.font = UIFont.footnote + } } @@ -51,7 +60,7 @@ private extension VerticalButton { enum Settings { static let cornerRadius = CGFloat(10) - static let edgeInsets = UIEdgeInsets(top: 5, left: 0, bottom: 5, right: 0) + static let horizontalEdgeInsets = CGFloat(5) static let labelPaddingTop = CGFloat(2) } } From ad6678a62f1a6c5fc31abf0d868ef4674a07f2dd Mon Sep 17 00:00:00 2001 From: iamgabrielma Date: Tue, 15 Nov 2022 15:17:32 +0900 Subject: [PATCH 12/21] Add ButtonConfiguration to EmptyStateViewController --- .../EmptyStateViewController/EmptyStateViewController.swift | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/WooCommerce/Classes/ViewRelated/ReusableViews/EmptyStateViewController/EmptyStateViewController.swift b/WooCommerce/Classes/ViewRelated/ReusableViews/EmptyStateViewController/EmptyStateViewController.swift index 541e3497e07..ff7e1dc97a6 100644 --- a/WooCommerce/Classes/ViewRelated/ReusableViews/EmptyStateViewController/EmptyStateViewController.swift +++ b/WooCommerce/Classes/ViewRelated/ReusableViews/EmptyStateViewController/EmptyStateViewController.swift @@ -307,7 +307,8 @@ private extension EmptyStateViewController { case .withSupportRequest(_, _, _, let buttonTitle, _): actionButton.isHidden = false actionButton.applyLinkButtonStyle() - actionButton.contentEdgeInsets = .zero + var configuration = UIButton.Configuration.filled() + configuration.contentInsets = .init(.zero) actionButton.setTitle(buttonTitle, for: .normal) } } From bc3c27e2d51be2ee815a56d5d86a3e4aa5caec66 Mon Sep 17 00:00:00 2001 From: iamgabrielma Date: Tue, 15 Nov 2022 15:19:37 +0900 Subject: [PATCH 13/21] Add ButtonConfiguration to CustomerNoteTableViewCell --- .../Customer Section/CustomerNoteTableViewCell.swift | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/WooCommerce/Classes/ViewRelated/Orders/Order Details/Customer Section/CustomerNoteTableViewCell.swift b/WooCommerce/Classes/ViewRelated/Orders/Order Details/Customer Section/CustomerNoteTableViewCell.swift index 9b8d31df1f5..0bb2c52a163 100644 --- a/WooCommerce/Classes/ViewRelated/Orders/Order Details/Customer Section/CustomerNoteTableViewCell.swift +++ b/WooCommerce/Classes/ViewRelated/Orders/Order Details/Customer Section/CustomerNoteTableViewCell.swift @@ -128,7 +128,8 @@ private extension CustomerNoteTableViewCell { addButton.setImage(.plusImage, for: .normal) addButton.contentHorizontalAlignment = .leading addButton.contentVerticalAlignment = .bottom - addButton.contentEdgeInsets = .zero + var configuration = UIButton.Configuration.filled() + configuration.contentInsets = .init(.zero) addButton.distributeTitleAndImage(spacing: Constants.buttonTitleAndImageSpacing) addButton.addTarget(self, action: #selector(addButtonTapped), for: .touchUpInside) } From 7490c9f37f8708108eb67b9c04ca627ac0230aba Mon Sep 17 00:00:00 2001 From: iamgabrielma Date: Tue, 15 Nov 2022 15:21:02 +0900 Subject: [PATCH 14/21] Add ButtonConfiguration to FilteredOrdersHeaderBar --- .../Orders/Order Filters/FilteredOrdersHeaderBar.swift | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/WooCommerce/Classes/ViewRelated/Orders/Order Filters/FilteredOrdersHeaderBar.swift b/WooCommerce/Classes/ViewRelated/Orders/Order Filters/FilteredOrdersHeaderBar.swift index 0fac3b8ce68..3d73d05f5e2 100644 --- a/WooCommerce/Classes/ViewRelated/Orders/Order Filters/FilteredOrdersHeaderBar.swift +++ b/WooCommerce/Classes/ViewRelated/Orders/Order Filters/FilteredOrdersHeaderBar.swift @@ -55,7 +55,8 @@ private extension FilteredOrdersHeaderBar { String.localizedStringWithFormat(Localization.buttonWithActiveFilters, numberOfFilters) filterButton.setTitle(title, for: .normal) - filterButton.contentEdgeInsets = .zero + var configuration = UIButton.Configuration.filled() + configuration.contentInsets = .init(.zero) filterButton.accessibilityIdentifier = "orders-filter-button" } From 1a40698810f278ac66a2b7e35696a943051c222d Mon Sep 17 00:00:00 2001 From: iamgabrielma Date: Tue, 15 Nov 2022 15:33:22 +0900 Subject: [PATCH 15/21] Add Configuration to SurveySubmittedViewController --- .../ViewRelated/Survey/SurveySubmittedViewController.swift | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/WooCommerce/Classes/ViewRelated/Survey/SurveySubmittedViewController.swift b/WooCommerce/Classes/ViewRelated/Survey/SurveySubmittedViewController.swift index 80288f88d6d..0ef33106118 100644 --- a/WooCommerce/Classes/ViewRelated/Survey/SurveySubmittedViewController.swift +++ b/WooCommerce/Classes/ViewRelated/Survey/SurveySubmittedViewController.swift @@ -93,7 +93,9 @@ private extension SurveySubmittedViewController { contactUsButton.applyLinkButtonStyle() contactUsButton.titleLabel?.applyCalloutStyle() - contactUsButton.contentEdgeInsets = .zero + var contactUsconfiguration = UIButton.Configuration.plain() + contactUsconfiguration.contentInsets = .init(.zero) + contactUsButton.configuration = contactUsconfiguration } /// Apply the correspondent localized texts to each component From dba89acef50df912bf1613a56bf3a08b96ce173f Mon Sep 17 00:00:00 2001 From: iamgabrielma Date: Tue, 15 Nov 2022 18:57:56 +0900 Subject: [PATCH 16/21] Add label as subview to UIButton By adding the UILabel as subview to the UIButton explicitely we avoid a crash on pinSubviewToAllEdgeMargins(_:) due not sharing a common ancestor. --- WooCommerce/Classes/Extensions/UIButton+Helpers.swift | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/WooCommerce/Classes/Extensions/UIButton+Helpers.swift b/WooCommerce/Classes/Extensions/UIButton+Helpers.swift index 5573388ecbf..edf2635504d 100644 --- a/WooCommerce/Classes/Extensions/UIButton+Helpers.swift +++ b/WooCommerce/Classes/Extensions/UIButton+Helpers.swift @@ -83,7 +83,7 @@ extension UIButton { /// Applies the Link Button Style: Clear BG / Brand Text Color /// func applyLinkButtonStyle(enableMultipleLines: Bool = false) { - var configuration = UIButton.Configuration.filled() + var configuration = UIButton.Configuration.plain() configuration.contentInsets = .init( top: Style.defaultInsets.top, leading: Style.defaultInsets.leading, @@ -166,6 +166,7 @@ extension UIButton { private func enableMultipleLines() { titleLabel?.lineBreakMode = .byWordWrapping if let label = titleLabel { + self.addSubview(label) pinSubviewToAllEdgeMargins(label) } } From cf68aa265fe6c5318582ba16d568dc9e82b1b111 Mon Sep 17 00:00:00 2001 From: iamgabrielma Date: Tue, 15 Nov 2022 18:59:42 +0900 Subject: [PATCH 17/21] Remove unnecessary var --- WooCommerce/Classes/Extensions/UIButton+Helpers.swift | 1 - 1 file changed, 1 deletion(-) diff --git a/WooCommerce/Classes/Extensions/UIButton+Helpers.swift b/WooCommerce/Classes/Extensions/UIButton+Helpers.swift index edf2635504d..cb7d9d0fcd7 100644 --- a/WooCommerce/Classes/Extensions/UIButton+Helpers.swift +++ b/WooCommerce/Classes/Extensions/UIButton+Helpers.swift @@ -181,6 +181,5 @@ private extension UIButton { static let defaultCornerRadius = CGFloat(8.0) static let defaultBorderWidth = CGFloat(1.0) static let defaultEdgeInsets = UIEdgeInsets(top: 12, left: 22, bottom: 12, right: 22) - static let defaultInsets = NSDirectionalEdgeInsets(top: 12, leading: 22, bottom: 12, trailing: 22) } } From 87d67d8434d0041d4a192a4f510ad769f3a96bc1 Mon Sep 17 00:00:00 2001 From: iamgabrielma Date: Wed, 16 Nov 2022 10:11:34 +0900 Subject: [PATCH 18/21] Add label as subview on UIActivityIndicatorView --- .../Classes/Extensions/UIButton+Helpers.swift | 48 ++++++++++++------- .../ButtonActivityIndicator.swift | 18 +++++++ 2 files changed, 49 insertions(+), 17 deletions(-) diff --git a/WooCommerce/Classes/Extensions/UIButton+Helpers.swift b/WooCommerce/Classes/Extensions/UIButton+Helpers.swift index cb7d9d0fcd7..cabc652f176 100644 --- a/WooCommerce/Classes/Extensions/UIButton+Helpers.swift +++ b/WooCommerce/Classes/Extensions/UIButton+Helpers.swift @@ -10,10 +10,10 @@ extension UIButton { func applyPrimaryButtonStyle() { var configuration = UIButton.Configuration.filled() configuration.contentInsets = .init( - top: Style.defaultInsets.top, - leading: Style.defaultInsets.leading, - bottom: Style.defaultInsets.bottom, - trailing: Style.defaultInsets.trailing + top: Style.defaultVerticalInsets, + leading: Style.defaultHorizontalInsets, + bottom: Style.defaultVerticalInsets, + trailing: Style.defaultHorizontalInsets ) layer.borderColor = UIColor.primaryButtonBorder.cgColor layer.borderWidth = Style.defaultBorderWidth @@ -47,10 +47,10 @@ extension UIButton { func applySecondaryButtonStyle() { var configuration = UIButton.Configuration.filled() configuration.contentInsets = .init( - top: Style.defaultInsets.top, - leading: Style.defaultInsets.leading, - bottom: Style.defaultInsets.bottom, - trailing: Style.defaultInsets.trailing + top: Style.defaultVerticalInsets, + leading: Style.defaultHorizontalInsets, + bottom: Style.defaultVerticalInsets, + trailing: Style.defaultHorizontalInsets ) backgroundColor = .secondaryButtonBackground layer.borderColor = UIColor.secondaryButtonBorder.cgColor @@ -85,10 +85,10 @@ extension UIButton { func applyLinkButtonStyle(enableMultipleLines: Bool = false) { var configuration = UIButton.Configuration.plain() configuration.contentInsets = .init( - top: Style.defaultInsets.top, - leading: Style.defaultInsets.leading, - bottom: Style.defaultInsets.bottom, - trailing: Style.defaultInsets.trailing + top: Style.defaultVerticalInsets, + leading: Style.defaultHorizontalInsets, + bottom: Style.defaultVerticalInsets, + trailing: Style.defaultHorizontalInsets ) backgroundColor = .clear tintColor = .accent @@ -113,8 +113,13 @@ extension UIButton { } func applyPaymentsModalCancelButtonStyle() { - configuration = UIButton.Configuration.plain() - configuration?.contentInsets = Style.defaultInsets + var configuration = UIButton.Configuration.plain() + configuration.contentInsets = .init( + top: Style.defaultVerticalInsets, + leading: Style.defaultHorizontalInsets, + bottom: Style.defaultVerticalInsets, + trailing: Style.defaultHorizontalInsets + ) backgroundColor = .tertiarySystemBackground layer.borderColor = UIColor.secondaryButtonBorder.cgColor layer.borderWidth = Style.defaultBorderWidth @@ -166,8 +171,16 @@ extension UIButton { private func enableMultipleLines() { titleLabel?.lineBreakMode = .byWordWrapping if let label = titleLabel { - self.addSubview(label) - pinSubviewToAllEdgeMargins(label) + if self.subviews.contains(where: { $0 == label }) { + pinSubviewToAllEdgeMargins(label) + } else { + DDLogWarn(""" + Failed attempt to pin button's title to the edges. + This is likely because the custom button title label was not added to its view hierarchy + See ButtonActivityIndicator as an example + """ + ) + } } } } @@ -180,6 +193,7 @@ private extension UIButton { struct Style { static let defaultCornerRadius = CGFloat(8.0) static let defaultBorderWidth = CGFloat(1.0) - static let defaultEdgeInsets = UIEdgeInsets(top: 12, left: 22, bottom: 12, right: 22) + static let defaultVerticalInsets = CGFloat(12) + static let defaultHorizontalInsets = CGFloat(22) } } diff --git a/WooCommerce/Classes/ViewRelated/ReusableViews/ButtonActivityIndicator.swift b/WooCommerce/Classes/ViewRelated/ReusableViews/ButtonActivityIndicator.swift index 9d76dcef719..4f084026ed0 100644 --- a/WooCommerce/Classes/ViewRelated/ReusableViews/ButtonActivityIndicator.swift +++ b/WooCommerce/Classes/ViewRelated/ReusableViews/ButtonActivityIndicator.swift @@ -6,6 +6,24 @@ final class ButtonActivityIndicator: UIButton { private let indicator: UIActivityIndicatorView = UIActivityIndicatorView(style: .medium) + // We're adding the UILabel as subview in order to avoid a crash when + // using large system fonts for accessibility. Trying to adapt the label + // to its container will fail as these do not share ancestor + // https://github.com/woocommerce/woocommerce-ios/pull/8094 + override init(frame: CGRect) { + super.init(frame: frame) + if let titleLabel { + addSubview(titleLabel) + } + } + + required init?(coder: NSCoder) { + super.init(coder: coder) + if let titleLabel { + addSubview(titleLabel) + } + } + override func layoutSubviews() { super.layoutSubviews() From 3fb678b30768adb54ead979e5d58e66599ecd839 Mon Sep 17 00:00:00 2001 From: iamgabrielma Date: Wed, 16 Nov 2022 10:42:15 +0900 Subject: [PATCH 19/21] Change CustomerNote button configuration to plain --- .../Customer Section/CustomerNoteTableViewCell.swift | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/WooCommerce/Classes/ViewRelated/Orders/Order Details/Customer Section/CustomerNoteTableViewCell.swift b/WooCommerce/Classes/ViewRelated/Orders/Order Details/Customer Section/CustomerNoteTableViewCell.swift index 0bb2c52a163..2ace3ee219e 100644 --- a/WooCommerce/Classes/ViewRelated/Orders/Order Details/Customer Section/CustomerNoteTableViewCell.swift +++ b/WooCommerce/Classes/ViewRelated/Orders/Order Details/Customer Section/CustomerNoteTableViewCell.swift @@ -128,8 +128,9 @@ private extension CustomerNoteTableViewCell { addButton.setImage(.plusImage, for: .normal) addButton.contentHorizontalAlignment = .leading addButton.contentVerticalAlignment = .bottom - var configuration = UIButton.Configuration.filled() + var configuration = UIButton.Configuration.plain() configuration.contentInsets = .init(.zero) + addButton.configuration = configuration addButton.distributeTitleAndImage(spacing: Constants.buttonTitleAndImageSpacing) addButton.addTarget(self, action: #selector(addButtonTapped), for: .touchUpInside) } From a6df43f0231d4a3bf6eff13bc76aea9b71a67772 Mon Sep 17 00:00:00 2001 From: iamgabrielma Date: Fri, 18 Nov 2022 10:51:54 +0900 Subject: [PATCH 20/21] Rename constants for readability --- .../Classes/Extensions/UIButton+Helpers.swift | 36 +++++++++---------- .../ReusableViews/VerticalButton.swift | 6 ++-- .../SurveySubmittedViewController.swift | 6 ++-- 3 files changed, 24 insertions(+), 24 deletions(-) diff --git a/WooCommerce/Classes/Extensions/UIButton+Helpers.swift b/WooCommerce/Classes/Extensions/UIButton+Helpers.swift index cabc652f176..153bca48249 100644 --- a/WooCommerce/Classes/Extensions/UIButton+Helpers.swift +++ b/WooCommerce/Classes/Extensions/UIButton+Helpers.swift @@ -10,10 +10,10 @@ extension UIButton { func applyPrimaryButtonStyle() { var configuration = UIButton.Configuration.filled() configuration.contentInsets = .init( - top: Style.defaultVerticalInsets, - leading: Style.defaultHorizontalInsets, - bottom: Style.defaultVerticalInsets, - trailing: Style.defaultHorizontalInsets + top: Style.verticalInset, + leading: Style.horizontalInset, + bottom: Style.verticalInset, + trailing: Style.horizontalInset ) layer.borderColor = UIColor.primaryButtonBorder.cgColor layer.borderWidth = Style.defaultBorderWidth @@ -47,10 +47,10 @@ extension UIButton { func applySecondaryButtonStyle() { var configuration = UIButton.Configuration.filled() configuration.contentInsets = .init( - top: Style.defaultVerticalInsets, - leading: Style.defaultHorizontalInsets, - bottom: Style.defaultVerticalInsets, - trailing: Style.defaultHorizontalInsets + top: Style.verticalInset, + leading: Style.horizontalInset, + bottom: Style.verticalInset, + trailing: Style.horizontalInset ) backgroundColor = .secondaryButtonBackground layer.borderColor = UIColor.secondaryButtonBorder.cgColor @@ -85,10 +85,10 @@ extension UIButton { func applyLinkButtonStyle(enableMultipleLines: Bool = false) { var configuration = UIButton.Configuration.plain() configuration.contentInsets = .init( - top: Style.defaultVerticalInsets, - leading: Style.defaultHorizontalInsets, - bottom: Style.defaultVerticalInsets, - trailing: Style.defaultHorizontalInsets + top: Style.verticalInset, + leading: Style.horizontalInset, + bottom: Style.verticalInset, + trailing: Style.horizontalInset ) backgroundColor = .clear tintColor = .accent @@ -115,10 +115,10 @@ extension UIButton { func applyPaymentsModalCancelButtonStyle() { var configuration = UIButton.Configuration.plain() configuration.contentInsets = .init( - top: Style.defaultVerticalInsets, - leading: Style.defaultHorizontalInsets, - bottom: Style.defaultVerticalInsets, - trailing: Style.defaultHorizontalInsets + top: Style.verticalInset, + leading: Style.horizontalInset, + bottom: Style.verticalInset, + trailing: Style.horizontalInset ) backgroundColor = .tertiarySystemBackground layer.borderColor = UIColor.secondaryButtonBorder.cgColor @@ -193,7 +193,7 @@ private extension UIButton { struct Style { static let defaultCornerRadius = CGFloat(8.0) static let defaultBorderWidth = CGFloat(1.0) - static let defaultVerticalInsets = CGFloat(12) - static let defaultHorizontalInsets = CGFloat(22) + static let verticalInset = CGFloat(12) + static let horizontalInset = CGFloat(22) } } diff --git a/WooCommerce/Classes/ViewRelated/ReusableViews/VerticalButton.swift b/WooCommerce/Classes/ViewRelated/ReusableViews/VerticalButton.swift index 6467d55923c..2ac6c9692c9 100644 --- a/WooCommerce/Classes/ViewRelated/ReusableViews/VerticalButton.swift +++ b/WooCommerce/Classes/ViewRelated/ReusableViews/VerticalButton.swift @@ -44,9 +44,9 @@ class VerticalButton: UIButton { var configuration = UIButton.Configuration.filled() configuration.contentInsets = .init( top: .zero, - leading: Settings.horizontalEdgeInsets, + leading: Settings.inset, bottom: .zero, - trailing: Settings.horizontalEdgeInsets + trailing: Settings.inset ) layer.cornerRadius = Settings.cornerRadius titleLabel?.font = UIFont.footnote @@ -60,7 +60,7 @@ private extension VerticalButton { enum Settings { static let cornerRadius = CGFloat(10) - static let horizontalEdgeInsets = CGFloat(5) + static let inset = CGFloat(5) static let labelPaddingTop = CGFloat(2) } } diff --git a/WooCommerce/Classes/ViewRelated/Survey/SurveySubmittedViewController.swift b/WooCommerce/Classes/ViewRelated/Survey/SurveySubmittedViewController.swift index 0ef33106118..e89d977dbdf 100644 --- a/WooCommerce/Classes/ViewRelated/Survey/SurveySubmittedViewController.swift +++ b/WooCommerce/Classes/ViewRelated/Survey/SurveySubmittedViewController.swift @@ -93,9 +93,9 @@ private extension SurveySubmittedViewController { contactUsButton.applyLinkButtonStyle() contactUsButton.titleLabel?.applyCalloutStyle() - var contactUsconfiguration = UIButton.Configuration.plain() - contactUsconfiguration.contentInsets = .init(.zero) - contactUsButton.configuration = contactUsconfiguration + var contactUsConfiguration = UIButton.Configuration.plain() + contactUsConfiguration.contentInsets = .init(.zero) + contactUsButton.configuration = contactUsConfiguration } /// Apply the correspondent localized texts to each component From db0bd1d875719953ee1f9cbefe5f9ef82d4e3132 Mon Sep 17 00:00:00 2001 From: iamgabrielma Date: Wed, 23 Nov 2022 19:30:46 +0900 Subject: [PATCH 21/21] Removed custom init from ButtonActivityIndicator --- .../Classes/Extensions/UIButton+Helpers.swift | 3 +-- .../ButtonActivityIndicator.swift | 18 ------------------ 2 files changed, 1 insertion(+), 20 deletions(-) diff --git a/WooCommerce/Classes/Extensions/UIButton+Helpers.swift b/WooCommerce/Classes/Extensions/UIButton+Helpers.swift index 153bca48249..8e9f83833a8 100644 --- a/WooCommerce/Classes/Extensions/UIButton+Helpers.swift +++ b/WooCommerce/Classes/Extensions/UIButton+Helpers.swift @@ -176,8 +176,7 @@ extension UIButton { } else { DDLogWarn(""" Failed attempt to pin button's title to the edges. - This is likely because the custom button title label was not added to its view hierarchy - See ButtonActivityIndicator as an example + This is likely because the custom button title label was not added to its view hierarchy. """ ) } diff --git a/WooCommerce/Classes/ViewRelated/ReusableViews/ButtonActivityIndicator.swift b/WooCommerce/Classes/ViewRelated/ReusableViews/ButtonActivityIndicator.swift index 4f084026ed0..9d76dcef719 100644 --- a/WooCommerce/Classes/ViewRelated/ReusableViews/ButtonActivityIndicator.swift +++ b/WooCommerce/Classes/ViewRelated/ReusableViews/ButtonActivityIndicator.swift @@ -6,24 +6,6 @@ final class ButtonActivityIndicator: UIButton { private let indicator: UIActivityIndicatorView = UIActivityIndicatorView(style: .medium) - // We're adding the UILabel as subview in order to avoid a crash when - // using large system fonts for accessibility. Trying to adapt the label - // to its container will fail as these do not share ancestor - // https://github.com/woocommerce/woocommerce-ios/pull/8094 - override init(frame: CGRect) { - super.init(frame: frame) - if let titleLabel { - addSubview(titleLabel) - } - } - - required init?(coder: NSCoder) { - super.init(coder: coder) - if let titleLabel { - addSubview(titleLabel) - } - } - override func layoutSubviews() { super.layoutSubviews()