Radio button changes

This commit is contained in:
Pfeil, Scott Robert 2019-10-23 11:32:34 -04:00
parent 7563269680
commit 0b364fa004
4 changed files with 77 additions and 44 deletions

View File

@ -10,7 +10,11 @@ import UIKit
@objcMembers public class RadioButton: Control, FormValidationFormFieldProtocol {
var diameter = 30
var diameter: CGFloat = 30 {
didSet {
widthConstraint?.constant = diameter
}
}
var enabledColor = UIColor.black
var disabledColor = UIColor.mfSilver()
@ -19,6 +23,9 @@ import UIKit
var fieldKey: String?
var formValue: Bool?
var isRequired: Bool = false
var widthConstraint: NSLayoutConstraint?
var heightConstraint: NSLayoutConstraint?
lazy var radioGroupName: String? = {
[unowned self] in
@ -37,12 +44,19 @@ import UIKit
open override func draw(_ rect: CGRect) {
guard let context = UIGraphicsGetCurrentContext() else { return }
context.addEllipse(in: CGRect(x: bounds.width*0.2, y: bounds.height*0.2, width: bounds.width*0.6, height: bounds.height*0.6))
context.setFillColor(isUserInteractionEnabled ? enabledColor.cgColor : disabledColor.cgColor)
context.fillPath()
let color = isEnabled ? enabledColor.cgColor : disabledColor.cgColor
layer.cornerRadius = bounds.width * 0.5
layer.borderColor = color
layer.borderWidth = bounds.width * 0.0333
if isSelected {
// Space around inner circle is 1/5 the size
context.addEllipse(in: CGRect(x: bounds.width*0.2, y: bounds.height*0.2, width: bounds.width*0.6, height: bounds.height*0.6))
context.setFillColor(color)
context.fillPath()
}
}
// MARK: - Inits
/// The action performed when tapped.
func tapAction() {
if let radioButtonModel = radioButtonModel {
radioButtonModel.selected(self)
@ -71,21 +85,24 @@ import UIKit
// MARK: - MVMViewProtocol
open override func setupView() {
super.setupView()
guard subviews.count == 0 else {
return
}
/*translatesAutoresizingMaskIntoConstraints = false
addSubview(radioButton)
isAccessibilityElement = true
accessibilityTraits = .none
accessibilityHint = MVMCoreUIUtility.hardcodedString(withKey: "radio_action_hint")
NSLayoutConstraint.constraintPinSubview(toSuperview: radioButton)
radioButton.performActionForCheck = { [weak self] in
self?.tapAction()
}*/
clipsToBounds = true
widthConstraint = widthAnchor.constraint(equalToConstant: 30)
widthConstraint?.isActive = true
heightConstraint = heightAnchor.constraint(equalTo: widthAnchor, multiplier: 1)
heightConstraint?.isActive = true
addTarget(self, action: #selector(tapAction), for: .touchUpInside)
isAccessibilityElement = true
accessibilityTraits = .button
accessibilityHint = MVMCoreUIUtility.hardcodedString(withKey: "radio_action_hint")
}
}
// MARK: - MVMCoreUIViewConstrainingProtocol
extension RadioButton: MVMCoreUIViewConstrainingProtocol {
public func needsToBeConstrained() -> Bool {
return true
}
}

View File

@ -314,14 +314,10 @@
[self.molecule updateView:size];
[MFStyler setMarginsForView:self size:size defaultHorizontal:self.updateViewHorizontalDefaults top:(self.updateViewVerticalDefaults ? self.topMarginPadding : 0) bottom:(self.updateViewVerticalDefaults ? self.bottomMarginPadding : 0)];
UIEdgeInsets margins = [MVMCoreUIUtility getMarginsForView:self];
if (self.updateViewHorizontalDefaults) {
[self setLeftPinConstant:margins.left];
[self setRightPinConstant:margins.right];
}
if (self.updateViewVerticalDefaults) {
[self setTopPinConstant:margins.top];
[self setBottomPinConstant:margins.bottom];
}
[self setLeftPinConstant:margins.left];
[self setRightPinConstant:margins.right];
[self setTopPinConstant:margins.top];
[self setBottomPinConstant:margins.bottom];
}
#pragma mark - MVMCoreUIMoleculeViewProtocol

View File

@ -10,20 +10,29 @@ import UIKit
public class Control: UIControl {
var json: [AnyHashable: Any]?
private var initialSetupPerformed = false
public override init(frame: CGRect) {
super.init(frame: .zero)
setupView()
initialSetup()
}
init() {
super.init(frame: .zero)
setupView()
initialSetup()
}
public required init?(coder: NSCoder) {
super.init(coder: coder)
setupView()
initialSetup()
}
public func initialSetup() {
if !initialSetupPerformed {
initialSetupPerformed = true
setupView()
}
}
}
@ -31,6 +40,7 @@ extension Control: MVMCoreViewProtocol {
public func updateView(_ size: CGFloat) {
}
/// Will be called only once.
public func setupView() {
translatesAutoresizingMaskIntoConstraints = false
insetsLayoutMarginsFromSafeArea = false

View File

@ -11,26 +11,36 @@ import UIKit
public class View: UIView {
var json: [AnyHashable: Any]?
public override init(frame: CGRect) {
super.init(frame: .zero)
setupView()
}
private var initialSetupPerformed = false
init() {
super.init(frame: .zero)
setupView()
public override init(frame: CGRect) {
super.init(frame: .zero)
initialSetup()
}
init() {
super.init(frame: .zero)
initialSetup()
}
public required init?(coder: NSCoder) {
super.init(coder: coder)
initialSetup()
}
public func initialSetup() {
if !initialSetupPerformed {
initialSetupPerformed = true
setupView()
}
}
}
public required init?(coder: NSCoder) {
super.init(coder: coder)
setupView()
}
}
extension View: MVMCoreViewProtocol {
public func updateView(_ size: CGFloat) {
}
/// Will be called only once.
public func setupView() {
translatesAutoresizingMaskIntoConstraints = false
insetsLayoutMarginsFromSafeArea = false