Pill button
This commit is contained in:
parent
a35b99b332
commit
c0ca81c568
@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
import UIKit
|
import UIKit
|
||||||
|
|
||||||
open class PillButton: Button {
|
open class PillButton: Button, MVMCoreUIViewConstrainingProtocol {
|
||||||
var size = MVMCoreUIUtility.getWidth()
|
var size = MVMCoreUIUtility.getWidth()
|
||||||
var buttonModel: ButtonModel? {
|
var buttonModel: ButtonModel? {
|
||||||
get { return model as? 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() {
|
public func stylePrimary() {
|
||||||
setTitleColor(.white, for: .normal)
|
setTitleColor(.white, for: .normal)
|
||||||
setTitleColor(.white, for: .disabled)
|
setTitleColor(.white, for: .disabled)
|
||||||
@ -44,14 +49,11 @@ open class PillButton: Button {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private func style() {
|
private func style() {
|
||||||
guard let model = buttonModel else { return }
|
switch buttonModel?.style {
|
||||||
if let style = model.style {
|
case .secondary:
|
||||||
switch style {
|
styleSecondary()
|
||||||
case .primary:
|
default:
|
||||||
stylePrimary()
|
stylePrimary()
|
||||||
case .secondary:
|
|
||||||
styleSecondary()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -66,9 +68,9 @@ open class PillButton: Button {
|
|||||||
public static func getHeight(for buttonSize: ButtonSize?, size: CGFloat) -> CGFloat {
|
public static func getHeight(for buttonSize: ButtonSize?, size: CGFloat) -> CGFloat {
|
||||||
switch buttonSize {
|
switch buttonSize {
|
||||||
case .tiny:
|
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:
|
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
|
// MARK: - ModelMoleculeViewProtocol
|
||||||
open override func setWithModel(_ model: MoleculeModelProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable : Any]?) {
|
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)
|
super.setWithModel(model, delegateObject, additionalData)
|
||||||
|
|
||||||
guard let model = model as? ButtonModel else { return }
|
guard let model = model as? ButtonModel else { return }
|
||||||
setTitle(model.title, for: .normal)
|
setTitle(model.title, for: .normal)
|
||||||
|
|
||||||
/*self.validationRequired = model.required ?? false
|
/*self.validationRequired = model.required ?? false
|
||||||
self.requiredGroupsList = model.requiredGroups
|
self.requiredGroupsList = model.requiredGroups
|
||||||
|
|
||||||
@ -100,7 +104,6 @@ open class PillButton: Button {
|
|||||||
let selfForm = self as? FormValidationEnableDisableProtocol {
|
let selfForm = self as? FormValidationEnableDisableProtocol {
|
||||||
FormValidator.setupValidation(molecule: selfForm, delegate: delegateObject?.formValidationProtocol)
|
FormValidator.setupValidation(molecule: selfForm, delegate: delegateObject?.formValidationProtocol)
|
||||||
}*/
|
}*/
|
||||||
style()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
open override class func estimatedHeight(forRow molecule: MoleculeModelProtocol?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? {
|
open override class func estimatedHeight(forRow molecule: MoleculeModelProtocol?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? {
|
||||||
@ -112,8 +115,13 @@ open class PillButton: Button {
|
|||||||
super.updateView(size)
|
super.updateView(size)
|
||||||
self.size = size
|
self.size = size
|
||||||
invalidateIntrinsicContentSize()
|
invalidateIntrinsicContentSize()
|
||||||
titleLabel?.font = MFStyler.fontB1(forWidth: size)
|
switch buttonModel?.size {
|
||||||
self.layer.cornerRadius = getInnerPadding()
|
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() {
|
open override func setupView() {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user