Pill button

This commit is contained in:
Pfeil, Scott Robert 2020-01-28 13:55:55 -05:00
parent a35b99b332
commit c0ca81c568

View File

@ -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() {