checkbox
This commit is contained in:
parent
d0ac49663a
commit
2b4d8b95c9
@ -11,6 +11,7 @@
|
||||
0105618E224BBE7700E1557D /* FormValidator+TextFields.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0105618B224BBE7700E1557D /* FormValidator+TextFields.swift */; };
|
||||
0105618F224BBE7700E1557D /* FormValidator+FormParams.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0105618C224BBE7700E1557D /* FormValidator+FormParams.swift */; };
|
||||
01056191224BBE8000E1557D /* FormValidationProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01056190224BBE7F00E1557D /* FormValidationProtocol.swift */; };
|
||||
013DAB042254FCE00092ABB7 /* CheckBoxWithLabel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 013DAB032254FCE00092ABB7 /* CheckBoxWithLabel.swift */; };
|
||||
01DF55E021F8FAA800CC099B /* MFTextFieldListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01DF55DF21F8FAA800CC099B /* MFTextFieldListView.swift */; };
|
||||
01DF567021FA5AB300CC099B /* TextFieldListFormViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01DF566F21FA5AB300CC099B /* TextFieldListFormViewController.swift */; };
|
||||
01E569D3223FFFA500327251 /* ThreeLayerViewController.swift in Headers */ = {isa = PBXBuildFile; fileRef = D2A5146A2214905000345BFB /* ThreeLayerViewController.swift */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
@ -167,6 +168,7 @@
|
||||
0105618B224BBE7700E1557D /* FormValidator+TextFields.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "FormValidator+TextFields.swift"; sourceTree = "<group>"; };
|
||||
0105618C224BBE7700E1557D /* FormValidator+FormParams.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "FormValidator+FormParams.swift"; sourceTree = "<group>"; };
|
||||
01056190224BBE7F00E1557D /* FormValidationProtocol.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FormValidationProtocol.swift; sourceTree = "<group>"; };
|
||||
013DAB032254FCE00092ABB7 /* CheckBoxWithLabel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CheckBoxWithLabel.swift; sourceTree = "<group>"; };
|
||||
01DF55DF21F8FAA800CC099B /* MFTextFieldListView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MFTextFieldListView.swift; sourceTree = "<group>"; };
|
||||
01DF566F21FA5AB300CC099B /* TextFieldListFormViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TextFieldListFormViewController.swift; sourceTree = "<group>"; };
|
||||
D206997521FB8A0B00CAE0DE /* MVMCoreUINavigationController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MVMCoreUINavigationController.h; sourceTree = "<group>"; };
|
||||
@ -595,6 +597,7 @@
|
||||
D22D1F19220341F50077CEC0 /* MVMCoreUICheckBox.m */,
|
||||
D22D1F44220496A30077CEC0 /* MVMCoreUISwitch.h */,
|
||||
D22D1F45220496A30077CEC0 /* MVMCoreUISwitch.m */,
|
||||
013DAB032254FCE00092ABB7 /* CheckBoxWithLabel.swift */,
|
||||
);
|
||||
path = Views;
|
||||
sourceTree = "<group>";
|
||||
@ -870,6 +873,7 @@
|
||||
D29770F221F7C6D600B2F0D0 /* TopLabelsAndBottomButtonsTableViewController.m in Sources */,
|
||||
DBC4391922442197001AB423 /* DashLine.swift in Sources */,
|
||||
D29DF29621E7ADB8003B2FB9 /* StackableViewController.m in Sources */,
|
||||
013DAB042254FCE00092ABB7 /* CheckBoxWithLabel.swift in Sources */,
|
||||
D22D1F1F220343560077CEC0 /* MVMCoreUICheckMarkView.m in Sources */,
|
||||
D282AAB4223FDDAE00C46919 /* MFLoadImageView.swift in Sources */,
|
||||
D29DF11721E6805F003B2FB9 /* UIColor+MFConvenience.m in Sources */,
|
||||
|
||||
31
MVMCoreUI/Atoms/Views/CheckBoxWithLabel.swift
Normal file
31
MVMCoreUI/Atoms/Views/CheckBoxWithLabel.swift
Normal file
@ -0,0 +1,31 @@
|
||||
//
|
||||
// ChecckBoxWithLabel.swift
|
||||
// MVMCoreUI
|
||||
//
|
||||
// Created by Suresh, Kamlesh on 4/3/19.
|
||||
// Copyright © 2019 Verizon Wireless. All rights reserved.
|
||||
//
|
||||
|
||||
import UIKit
|
||||
|
||||
@objcMembers public class CheckBoxWithLabel: ViewConstrainingView {
|
||||
let mvmCheckBox = MVMCoreUICheckBox(frame: .zero)
|
||||
|
||||
public init() {
|
||||
super.init(frame: .zero)
|
||||
}
|
||||
|
||||
public required init?(coder decoder: NSCoder) {
|
||||
super.init(coder: decoder)
|
||||
}
|
||||
|
||||
public override func setupView() {
|
||||
super.setupView()
|
||||
addConstrainedView(mvmCheckBox)
|
||||
}
|
||||
|
||||
override open func setWithJSON(_ json: [AnyHashable: Any]?, delegate: NSObject?, additionalData: [AnyHashable: Any]?) {
|
||||
super.setWithJSON(json, delegate: delegate, additionalData: additionalData)
|
||||
mvmCheckBox.setWithJSON(json, delegate: delegate, additionalData: additionalData)
|
||||
}
|
||||
}
|
||||
@ -59,4 +59,7 @@
|
||||
- (void)setValueForAccessibilityText:(nullable NSString *)text;
|
||||
- (void)hideDescriptionLabelAndPinCheckboxToRight;
|
||||
|
||||
// Molecule Design
|
||||
- (void)setWithJSON:(nullable NSDictionary *)json delegate:(nullable NSObject *)delegate additionalData:(nullable NSDictionary *)additionalData;
|
||||
|
||||
@end
|
||||
|
||||
@ -16,10 +16,13 @@
|
||||
#import "UIColor+MFConvenience.h"
|
||||
#import "MVMCoreUIUtility.h"
|
||||
#import "MFStyler.h"
|
||||
#import <MVMCoreUI/MVMCoreUI-Swift.h>
|
||||
|
||||
|
||||
static const CGFloat FaultTolerance = 20.f;
|
||||
static const CGFloat CheckBoxHeightWidth = 18.0;
|
||||
@interface MVMCoreUICheckBox ()
|
||||
|
||||
@interface MVMCoreUICheckBox () <FormValidationProtocol>
|
||||
|
||||
@property (nonatomic, readwrite) BOOL isSelected;
|
||||
@property (weak, nonatomic) UIView *checkedSquare;
|
||||
@ -38,12 +41,32 @@ static const CGFloat CheckBoxHeightWidth = 18.0;
|
||||
@property (nullable, strong, nonatomic) NSLayoutConstraint *checkboxWidth;
|
||||
@property (nullable, strong, nonatomic) NSLayoutConstraint *checkboxHeight;
|
||||
|
||||
@property (nonatomic) BOOL isRequired;
|
||||
@property (nullable, strong, nonatomic) NSString *fieldKey;
|
||||
@property (nullable, weak) id <FormValidationProtocol> delegate;
|
||||
|
||||
@end
|
||||
|
||||
@implementation MVMCoreUICheckBox
|
||||
|
||||
#pragma mark - convenient class methods
|
||||
|
||||
- (void)setWithJSON:(nullable NSDictionary *)json delegate:(nullable NSObject *)delegate additionalData:(nullable NSDictionary *)additionalData {
|
||||
[FormValidator setupValidationWithMolecule:self delegate:(id<FormValidationProtocol>)delegate];
|
||||
self.delegate = (id<FormValidationProtocol>)delegate;
|
||||
self.fieldKey = [json stringForKey:@"fieldKey"];
|
||||
self.isRequired = [json boolForKey:@"required"];
|
||||
|
||||
NSString *checkedColorHex = [json string:@"checkedColor"];
|
||||
NSString *unCheckedColorHex = [json string:@"unCheckedColor"];
|
||||
|
||||
UIColor *checkedColor = checkedColorHex ? [UIColor mfGetColorForHex:checkedColorHex]: [UIColor blackColor];
|
||||
UIColor *unCheckedColor = unCheckedColorHex ? [UIColor mfGetColorForHex:unCheckedColorHex]: [UIColor clearColor];
|
||||
NSString *label = [json string:@"label"];
|
||||
|
||||
[self setupWithCheckedColor:checkedColor unCheckColor:unCheckedColor text:label];
|
||||
}
|
||||
|
||||
+ (instancetype)mfCheckBox {
|
||||
MVMCoreUICheckBox *checkBox = [[self alloc] initWithFrame:CGRectZero];
|
||||
checkBox.translatesAutoresizingMaskIntoConstraints = NO;
|
||||
@ -68,6 +91,23 @@ static const CGFloat CheckBoxHeightWidth = 18.0;
|
||||
return checkBox;
|
||||
}
|
||||
|
||||
#pragma mark - FormValidationProtocol
|
||||
|
||||
- (BOOL)isValidField {
|
||||
if (self.isRequired) {
|
||||
return self.isSelected;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
- (nullable NSString *)formFieldName {
|
||||
return self.fieldKey;
|
||||
}
|
||||
|
||||
- (nullable id)formFieldValue {
|
||||
return @(self.isSelected);
|
||||
}
|
||||
|
||||
#pragma mark - inits
|
||||
|
||||
- (instancetype)initWithCheckedColor:(UIColor *)checkedColor unCheckColor:(UIColor *)unCheckedColor text:(NSString *)text {
|
||||
@ -253,7 +293,7 @@ static const CGFloat CheckBoxHeightWidth = 18.0;
|
||||
[self setSelected:selected animated:animated runBlock:YES];
|
||||
}
|
||||
|
||||
- (void)setSelected:(BOOL)selected animated:(BOOL)animated runBlock:(BOOL)runBlock{
|
||||
- (void)setSelected:(BOOL)selected animated:(BOOL)animated runBlock:(BOOL)runBlock {
|
||||
[self addAccessibilityLabel:selected];
|
||||
|
||||
self.isSelected = selected;
|
||||
@ -271,6 +311,9 @@ static const CGFloat CheckBoxHeightWidth = 18.0;
|
||||
} completion:nil];
|
||||
[self.checkMark updateCheckSelected:NO animated:animated];
|
||||
}
|
||||
|
||||
FormValidator *formValidator = [FormValidator getFormValidatorForDelegate:self.delegate];
|
||||
[formValidator enableByValidation];
|
||||
}
|
||||
|
||||
- (void)setColor:(nullable UIColor *)color forState:(UIControlState)state {
|
||||
|
||||
@ -47,4 +47,7 @@
|
||||
// For setting up the view.
|
||||
- (void)setupView;
|
||||
|
||||
// Add a View Constraining View
|
||||
- (void)addConstrainedView:(nonnull UIView *)view;
|
||||
|
||||
@end
|
||||
|
||||
@ -28,28 +28,30 @@
|
||||
ViewConstrainingView *constrainingView = [[ViewConstrainingView alloc] initWithFrame:CGRectZero];
|
||||
constrainingView.translatesAutoresizingMaskIntoConstraints = NO;
|
||||
constrainingView.backgroundColor = [UIColor clearColor];
|
||||
|
||||
[constrainingView addConstrainedView:view];
|
||||
return constrainingView;
|
||||
}
|
||||
|
||||
- (void)addConstrainedView:(nonnull UIView *)view {
|
||||
view.translatesAutoresizingMaskIntoConstraints = NO;
|
||||
[constrainingView addSubview:view];
|
||||
constrainingView.constrainedView = view;
|
||||
[self addSubview:view];
|
||||
self.constrainedView = view;
|
||||
|
||||
NSLayoutConstraint *leftPin = [view.leftAnchor constraintEqualToAnchor:constrainingView.leftAnchor];
|
||||
constrainingView.leftPin = leftPin;
|
||||
NSLayoutConstraint *leftPin = [view.leftAnchor constraintEqualToAnchor:self.leftAnchor];
|
||||
self.leftPin = leftPin;
|
||||
leftPin.active = YES;
|
||||
|
||||
NSLayoutConstraint *topPin = [view.topAnchor constraintEqualToAnchor:constrainingView.topAnchor];
|
||||
constrainingView.topPin = topPin;
|
||||
NSLayoutConstraint *topPin = [view.topAnchor constraintEqualToAnchor:self.topAnchor];
|
||||
self.topPin = topPin;
|
||||
topPin.active = YES;
|
||||
|
||||
NSLayoutConstraint *bottomPin = [constrainingView.bottomAnchor constraintEqualToAnchor:view.bottomAnchor];
|
||||
constrainingView.bottomPin = bottomPin;
|
||||
NSLayoutConstraint *bottomPin = [self.bottomAnchor constraintEqualToAnchor:view.bottomAnchor];
|
||||
self.bottomPin = bottomPin;
|
||||
bottomPin.active = YES;
|
||||
|
||||
NSLayoutConstraint *rightPin = [constrainingView.rightAnchor constraintEqualToAnchor:view.rightAnchor];
|
||||
constrainingView.rightPin = rightPin;
|
||||
NSLayoutConstraint *rightPin = [self.rightAnchor constraintEqualToAnchor:view.rightAnchor];
|
||||
self.rightPin = rightPin;
|
||||
rightPin.active = YES;
|
||||
|
||||
return constrainingView;
|
||||
}
|
||||
|
||||
- (void)pinToSuperView {
|
||||
|
||||
@ -32,7 +32,8 @@
|
||||
@"standardFooter": StandardFooterView.class,
|
||||
@"caretView": CaretView.class,
|
||||
@"caretButton": CaretButton.class,
|
||||
@"textField" : MFTextField.class
|
||||
@"textField" : MFTextField.class,
|
||||
@"checkbox" : CheckBoxWithLabel.class
|
||||
} mutableCopy];
|
||||
});
|
||||
return mapping;
|
||||
|
||||
@ -15,5 +15,5 @@ import Foundation
|
||||
@objc optional func enableField(_ enable: Bool)
|
||||
|
||||
@objc optional func formFieldName() -> String?
|
||||
@objc optional func formFieldValue() -> String?
|
||||
@objc optional func formFieldValue() -> Any?
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user