From c0ca81c5685c3b06958b2b3a9b02b3d3cc0e111c Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Tue, 28 Jan 2020 13:55:55 -0500 Subject: [PATCH] Pill button --- MVMCoreUI/Atoms/Buttons/PillButton.swift | 38 ++++++++++++++---------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/MVMCoreUI/Atoms/Buttons/PillButton.swift b/MVMCoreUI/Atoms/Buttons/PillButton.swift index 6cf21c40..8bda4b20 100644 --- a/MVMCoreUI/Atoms/Buttons/PillButton.swift +++ b/MVMCoreUI/Atoms/Buttons/PillButton.swift @@ -8,7 +8,7 @@ import UIKit -open class PillButton: Button { +open class PillButton: Button, MVMCoreUIViewConstrainingProtocol { var size = MVMCoreUIUtility.getWidth() var buttonModel: ButtonModel? { get { return model as? ButtonModel } @@ -20,6 +20,11 @@ open class PillButton: Button { } } + private enum ButtonHeight: CGFloat { + case tiny = 20 + case standard = 42 + } + public func stylePrimary() { setTitleColor(.white, for: .normal) setTitleColor(.white, for: .disabled) @@ -44,14 +49,11 @@ open class PillButton: Button { } private func style() { - guard let model = buttonModel else { return } - if let style = model.style { - switch style { - case .primary: - stylePrimary() - case .secondary: - styleSecondary() - } + switch buttonModel?.style { + case .secondary: + styleSecondary() + default: + stylePrimary() } } @@ -66,9 +68,9 @@ open class PillButton: Button { public static func getHeight(for buttonSize: ButtonSize?, size: CGFloat) -> CGFloat { switch buttonSize { case .tiny: - return MFSizeObject(standardSize: 20, standardiPadPortraitSize: 34, iPadProLandscapeSize: 38)?.getValueBased(onSize: size) ?? 20 + return MFSizeObject(standardSize: ButtonHeight.tiny.rawValue, standardiPadPortraitSize: 34, iPadProLandscapeSize: 38)?.getValueBased(onSize: size) ?? 20 default: - return MFSizeObject(standardSize: 42, standardiPadPortraitSize: 46, iPadProLandscapeSize: 50)?.getValueBased(onSize: size) ?? 42 + return MFSizeObject(standardSize: ButtonHeight.standard.rawValue, standardiPadPortraitSize: 46, iPadProLandscapeSize: 50)?.getValueBased(onSize: size) ?? 42 } } @@ -89,10 +91,12 @@ open class PillButton: Button { // MARK: - ModelMoleculeViewProtocol open override func setWithModel(_ model: MoleculeModelProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable : Any]?) { + // The button will get styled in the enable check in super. super.setWithModel(model, delegateObject, additionalData) + guard let model = model as? ButtonModel else { return } setTitle(model.title, for: .normal) - + /*self.validationRequired = model.required ?? false self.requiredGroupsList = model.requiredGroups @@ -100,7 +104,6 @@ open class PillButton: Button { let selfForm = self as? FormValidationEnableDisableProtocol { FormValidator.setupValidation(molecule: selfForm, delegate: delegateObject?.formValidationProtocol) }*/ - style() } open override class func estimatedHeight(forRow molecule: MoleculeModelProtocol?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? { @@ -112,8 +115,13 @@ open class PillButton: Button { super.updateView(size) self.size = size invalidateIntrinsicContentSize() - titleLabel?.font = MFStyler.fontB1(forWidth: size) - self.layer.cornerRadius = getInnerPadding() + switch buttonModel?.size { + case .tiny: + titleLabel?.font = MFFonts.mfFont75Bd(11 * (intrinsicContentSize.height / ButtonHeight.tiny.rawValue)) + default: + titleLabel?.font = MFFonts.mfFont75Bd(13 * (intrinsicContentSize.height / ButtonHeight.standard.rawValue)) + } + layer.cornerRadius = getInnerPadding() } open override func setupView() {