Radio button changes
This commit is contained in:
parent
7563269680
commit
0b364fa004
@ -10,7 +10,11 @@ import UIKit
|
|||||||
|
|
||||||
@objcMembers public class RadioButton: Control, FormValidationFormFieldProtocol {
|
@objcMembers public class RadioButton: Control, FormValidationFormFieldProtocol {
|
||||||
|
|
||||||
var diameter = 30
|
var diameter: CGFloat = 30 {
|
||||||
|
didSet {
|
||||||
|
widthConstraint?.constant = diameter
|
||||||
|
}
|
||||||
|
}
|
||||||
var enabledColor = UIColor.black
|
var enabledColor = UIColor.black
|
||||||
var disabledColor = UIColor.mfSilver()
|
var disabledColor = UIColor.mfSilver()
|
||||||
|
|
||||||
@ -20,6 +24,9 @@ import UIKit
|
|||||||
var formValue: Bool?
|
var formValue: Bool?
|
||||||
var isRequired: Bool = false
|
var isRequired: Bool = false
|
||||||
|
|
||||||
|
var widthConstraint: NSLayoutConstraint?
|
||||||
|
var heightConstraint: NSLayoutConstraint?
|
||||||
|
|
||||||
lazy var radioGroupName: String? = {
|
lazy var radioGroupName: String? = {
|
||||||
[unowned self] in
|
[unowned self] in
|
||||||
return json?.optionalStringForKey("radioGroupName") ?? json?.optionalStringForKey("fieldKey")
|
return json?.optionalStringForKey("radioGroupName") ?? json?.optionalStringForKey("fieldKey")
|
||||||
@ -37,12 +44,19 @@ import UIKit
|
|||||||
|
|
||||||
open override func draw(_ rect: CGRect) {
|
open override func draw(_ rect: CGRect) {
|
||||||
guard let context = UIGraphicsGetCurrentContext() else { return }
|
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))
|
let color = isEnabled ? enabledColor.cgColor : disabledColor.cgColor
|
||||||
context.setFillColor(isUserInteractionEnabled ? enabledColor.cgColor : disabledColor.cgColor)
|
layer.cornerRadius = bounds.width * 0.5
|
||||||
context.fillPath()
|
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() {
|
func tapAction() {
|
||||||
if let radioButtonModel = radioButtonModel {
|
if let radioButtonModel = radioButtonModel {
|
||||||
radioButtonModel.selected(self)
|
radioButtonModel.selected(self)
|
||||||
@ -71,21 +85,24 @@ import UIKit
|
|||||||
// MARK: - MVMViewProtocol
|
// MARK: - MVMViewProtocol
|
||||||
open override func setupView() {
|
open override func setupView() {
|
||||||
super.setupView()
|
super.setupView()
|
||||||
guard subviews.count == 0 else {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
/*translatesAutoresizingMaskIntoConstraints = false
|
clipsToBounds = true
|
||||||
addSubview(radioButton)
|
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
|
isAccessibilityElement = true
|
||||||
accessibilityTraits = .none
|
accessibilityTraits = .button
|
||||||
accessibilityHint = MVMCoreUIUtility.hardcodedString(withKey: "radio_action_hint")
|
accessibilityHint = MVMCoreUIUtility.hardcodedString(withKey: "radio_action_hint")
|
||||||
NSLayoutConstraint.constraintPinSubview(toSuperview: radioButton)
|
}
|
||||||
|
}
|
||||||
|
|
||||||
radioButton.performActionForCheck = { [weak self] in
|
// MARK: - MVMCoreUIViewConstrainingProtocol
|
||||||
self?.tapAction()
|
extension RadioButton: MVMCoreUIViewConstrainingProtocol {
|
||||||
}*/
|
public func needsToBeConstrained() -> Bool {
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -314,14 +314,10 @@
|
|||||||
[self.molecule updateView:size];
|
[self.molecule updateView:size];
|
||||||
[MFStyler setMarginsForView:self size:size defaultHorizontal:self.updateViewHorizontalDefaults top:(self.updateViewVerticalDefaults ? self.topMarginPadding : 0) bottom:(self.updateViewVerticalDefaults ? self.bottomMarginPadding : 0)];
|
[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];
|
UIEdgeInsets margins = [MVMCoreUIUtility getMarginsForView:self];
|
||||||
if (self.updateViewHorizontalDefaults) {
|
[self setLeftPinConstant:margins.left];
|
||||||
[self setLeftPinConstant:margins.left];
|
[self setRightPinConstant:margins.right];
|
||||||
[self setRightPinConstant:margins.right];
|
[self setTopPinConstant:margins.top];
|
||||||
}
|
[self setBottomPinConstant:margins.bottom];
|
||||||
if (self.updateViewVerticalDefaults) {
|
|
||||||
[self setTopPinConstant:margins.top];
|
|
||||||
[self setBottomPinConstant:margins.bottom];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma mark - MVMCoreUIMoleculeViewProtocol
|
#pragma mark - MVMCoreUIMoleculeViewProtocol
|
||||||
|
|||||||
@ -11,19 +11,28 @@ import UIKit
|
|||||||
public class Control: UIControl {
|
public class Control: UIControl {
|
||||||
var json: [AnyHashable: Any]?
|
var json: [AnyHashable: Any]?
|
||||||
|
|
||||||
|
private var initialSetupPerformed = false
|
||||||
|
|
||||||
public override init(frame: CGRect) {
|
public override init(frame: CGRect) {
|
||||||
super.init(frame: .zero)
|
super.init(frame: .zero)
|
||||||
setupView()
|
initialSetup()
|
||||||
}
|
}
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
super.init(frame: .zero)
|
super.init(frame: .zero)
|
||||||
setupView()
|
initialSetup()
|
||||||
}
|
}
|
||||||
|
|
||||||
public required init?(coder: NSCoder) {
|
public required init?(coder: NSCoder) {
|
||||||
super.init(coder: coder)
|
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) {
|
public func updateView(_ size: CGFloat) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Will be called only once.
|
||||||
public func setupView() {
|
public func setupView() {
|
||||||
translatesAutoresizingMaskIntoConstraints = false
|
translatesAutoresizingMaskIntoConstraints = false
|
||||||
insetsLayoutMarginsFromSafeArea = false
|
insetsLayoutMarginsFromSafeArea = false
|
||||||
|
|||||||
@ -11,26 +11,36 @@ import UIKit
|
|||||||
public class View: UIView {
|
public class View: UIView {
|
||||||
var json: [AnyHashable: Any]?
|
var json: [AnyHashable: Any]?
|
||||||
|
|
||||||
|
private var initialSetupPerformed = false
|
||||||
|
|
||||||
public override init(frame: CGRect) {
|
public override init(frame: CGRect) {
|
||||||
super.init(frame: .zero)
|
super.init(frame: .zero)
|
||||||
setupView()
|
initialSetup()
|
||||||
}
|
}
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
super.init(frame: .zero)
|
super.init(frame: .zero)
|
||||||
setupView()
|
initialSetup()
|
||||||
}
|
}
|
||||||
|
|
||||||
public required init?(coder: NSCoder) {
|
public required init?(coder: NSCoder) {
|
||||||
super.init(coder: coder)
|
super.init(coder: coder)
|
||||||
setupView()
|
initialSetup()
|
||||||
|
}
|
||||||
|
|
||||||
|
public func initialSetup() {
|
||||||
|
if !initialSetupPerformed {
|
||||||
|
initialSetupPerformed = true
|
||||||
|
setupView()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
extension View: MVMCoreViewProtocol {
|
extension View: MVMCoreViewProtocol {
|
||||||
public func updateView(_ size: CGFloat) {
|
public func updateView(_ size: CGFloat) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Will be called only once.
|
||||||
public func setupView() {
|
public func setupView() {
|
||||||
translatesAutoresizingMaskIntoConstraints = false
|
translatesAutoresizingMaskIntoConstraints = false
|
||||||
insetsLayoutMarginsFromSafeArea = false
|
insetsLayoutMarginsFromSafeArea = false
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user