correction.
This commit is contained in:
parent
d2d4e3d42c
commit
494df94d3a
@ -155,28 +155,29 @@ import UIKit
|
|||||||
fatalError("DigitEntryField xib has not been implemented")
|
fatalError("DigitEntryField xib has not been implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
public init(numberOfDigits: Int) {
|
public override init(frame: CGRect) {
|
||||||
super.init(frame: .zero)
|
super.init(frame: frame)
|
||||||
|
|
||||||
setup()
|
setup()
|
||||||
|
}
|
||||||
|
|
||||||
|
public convenience init() {
|
||||||
|
self.init(frame: .zero)
|
||||||
|
}
|
||||||
|
|
||||||
|
public convenience init(numberOfDigits: Int) {
|
||||||
|
self.init(frame: .zero)
|
||||||
|
|
||||||
|
|
||||||
self.numberOfDigits = numberOfDigits
|
self.numberOfDigits = numberOfDigits
|
||||||
buildTextFieldsView(size: MVMCoreUISplitViewController.getDetailViewWidth())
|
buildTextFieldsView(size: MVMCoreUISplitViewController.getDetailViewWidth())
|
||||||
}
|
}
|
||||||
|
|
||||||
public init(numberOfDigits: Int, bothDelegates delegates: (UITextFieldDelegate & MFTextFieldDelegate)?) {
|
public init(numberOfDigits: Int, bothDelegates delegate: (UITextFieldDelegate & MFTextFieldDelegate)?, size: CGFloat? = nil) {
|
||||||
super.init(bothDelegates: delegates as? (TextFieldDelegate & UITextFieldDelegate))
|
|
||||||
|
|
||||||
setup()
|
|
||||||
self.numberOfDigits = numberOfDigits
|
|
||||||
buildTextFieldsView(size: MVMCoreUISplitViewController.getDetailViewWidth())
|
|
||||||
}
|
|
||||||
|
|
||||||
public init(numberOfDigits: Int, bothDelegates delegate: (UITextFieldDelegate & MFTextFieldDelegate)?, size: CGFloat) {
|
|
||||||
super.init(bothDelegates: delegate as? (TextFieldDelegate & UITextFieldDelegate))
|
super.init(bothDelegates: delegate as? (TextFieldDelegate & UITextFieldDelegate))
|
||||||
|
|
||||||
setup()
|
setup()
|
||||||
self.numberOfDigits = numberOfDigits
|
self.numberOfDigits = numberOfDigits
|
||||||
buildTextFieldsView(size: size)
|
buildTextFieldsView(size: size ?? MVMCoreUISplitViewController.getDetailViewWidth())
|
||||||
}
|
}
|
||||||
|
|
||||||
open override func setupFieldContainerContent(_ container: UIView) {
|
open override func setupFieldContainerContent(_ container: UIView) {
|
||||||
|
|||||||
@ -181,7 +181,7 @@ import UIKit
|
|||||||
|
|
||||||
addSubview(feedbackLabel)
|
addSubview(feedbackLabel)
|
||||||
|
|
||||||
feedbackLabel.heightAnchor.constraint(greaterThanOrEqualToConstant: 0).isActive = true
|
feedbackLabel.heightAnchor.constraint(greaterThanOrEqualToConstant: 15).isActive = true
|
||||||
feedbackLabel.topAnchor.constraint(equalTo: fieldContainer.bottomAnchor, constant: PaddingOne).isActive = true
|
feedbackLabel.topAnchor.constraint(equalTo: fieldContainer.bottomAnchor, constant: PaddingOne).isActive = true
|
||||||
feedbackLabelLeading = feedbackLabel.leadingAnchor.constraint(equalTo: layoutMarginsGuide.leadingAnchor)
|
feedbackLabelLeading = feedbackLabel.leadingAnchor.constraint(equalTo: layoutMarginsGuide.leadingAnchor)
|
||||||
feedbackLabelLeading?.isActive = true
|
feedbackLabelLeading?.isActive = true
|
||||||
@ -220,7 +220,7 @@ import UIKit
|
|||||||
open override func layoutSubviews() {
|
open override func layoutSubviews() {
|
||||||
super.layoutSubviews()
|
super.layoutSubviews()
|
||||||
|
|
||||||
resizeBottomBar(size: 1)
|
refreshUI(bottomBarSize: 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
@ -252,17 +252,6 @@ import UIKit
|
|||||||
|
|
||||||
func resizeBottomBar(size: CGFloat) {
|
func resizeBottomBar(size: CGFloat) {
|
||||||
|
|
||||||
// if bottomBar.frame.height == 1 {
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
|
|
||||||
// let bottomBarHeight = CABasicAnimation(keyPath: "bounds.size.height")
|
|
||||||
// bottomBarHeight.fromValue = 1
|
|
||||||
// bottomBarHeight.toValue = 4
|
|
||||||
// bottomBarHeight.duration = 0.1
|
|
||||||
// bottomBarHeight.isRemovedOnCompletion = false
|
|
||||||
// bottomBar.add(bottomBarHeight, forKey: "bottomBarHeight")
|
|
||||||
|
|
||||||
if let fieldBounds = fieldContainer?.bounds {
|
if let fieldBounds = fieldContainer?.bounds {
|
||||||
bottomBar.frame = CGRect(x: 0, y: fieldBounds.height - size, width: fieldBounds.width, height: size)
|
bottomBar.frame = CGRect(x: 0, y: fieldBounds.height - size, width: fieldBounds.width, height: size)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -26,33 +26,6 @@ import UIKit
|
|||||||
|
|
||||||
private(set) var textField: UITextField?
|
private(set) var textField: UITextField?
|
||||||
|
|
||||||
//--------------------------------------------------
|
|
||||||
// MARK: - Delegate Properties
|
|
||||||
//--------------------------------------------------
|
|
||||||
|
|
||||||
/// The delegate and block for validation. Validates if the text that the user has entered is valid or not. Checked after each change if there is a delegate.
|
|
||||||
public weak var mfTextFieldDelegate: TextFieldDelegate? {
|
|
||||||
didSet {
|
|
||||||
if mfTextFieldDelegate != nil && !observingForChanges {
|
|
||||||
observingForChanges = true
|
|
||||||
NotificationCenter.default.addObserver(self, selector: #selector(valueChanged), name: UITextField.textDidChangeNotification, object: textField)
|
|
||||||
NotificationCenter.default.addObserver(self, selector: #selector(endInputing), name: UITextField.textDidEndEditingNotification, object: textField)
|
|
||||||
NotificationCenter.default.addObserver(self, selector: #selector(startEditing), name: UITextField.textDidBeginEditingNotification, object: textField)
|
|
||||||
} else if mfTextFieldDelegate == nil && observingForChanges {
|
|
||||||
observingForChanges = false
|
|
||||||
NotificationCenter.default.removeObserver(self, name: UITextField.textDidChangeNotification, object: textField)
|
|
||||||
NotificationCenter.default.removeObserver(self, name: UITextField.textDidEndEditingNotification, object: textField)
|
|
||||||
NotificationCenter.default.removeObserver(self, name: UITextField.textDidBeginEditingNotification, object: textField)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// If you're using a MFViewController, you must set this to it
|
|
||||||
public weak var uiTextFieldDelegate: UITextFieldDelegate? {
|
|
||||||
get { return textField?.delegate }
|
|
||||||
set { textField?.delegate = newValue }
|
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Properties
|
// MARK: - Properties
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
@ -94,6 +67,33 @@ import UIKit
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------
|
||||||
|
// MARK: - Delegate Properties
|
||||||
|
//--------------------------------------------------
|
||||||
|
|
||||||
|
/// The delegate and block for validation. Validates if the text that the user has entered is valid or not. Checked after each change if there is a delegate.
|
||||||
|
public weak var mfTextFieldDelegate: TextFieldDelegate? {
|
||||||
|
didSet {
|
||||||
|
if mfTextFieldDelegate != nil && !observingForChanges {
|
||||||
|
observingForChanges = true
|
||||||
|
NotificationCenter.default.addObserver(self, selector: #selector(valueChanged), name: UITextField.textDidChangeNotification, object: textField)
|
||||||
|
NotificationCenter.default.addObserver(self, selector: #selector(endInputing), name: UITextField.textDidEndEditingNotification, object: textField)
|
||||||
|
NotificationCenter.default.addObserver(self, selector: #selector(startEditing), name: UITextField.textDidBeginEditingNotification, object: textField)
|
||||||
|
} else if mfTextFieldDelegate == nil && observingForChanges {
|
||||||
|
observingForChanges = false
|
||||||
|
NotificationCenter.default.removeObserver(self, name: UITextField.textDidChangeNotification, object: textField)
|
||||||
|
NotificationCenter.default.removeObserver(self, name: UITextField.textDidEndEditingNotification, object: textField)
|
||||||
|
NotificationCenter.default.removeObserver(self, name: UITextField.textDidBeginEditingNotification, object: textField)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// If you're using a MFViewController, you must set this to it
|
||||||
|
public weak var uiTextFieldDelegate: UITextFieldDelegate? {
|
||||||
|
get { return textField?.delegate }
|
||||||
|
set { textField?.delegate = newValue }
|
||||||
|
}
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Constraints
|
// MARK: - Constraints
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
@ -109,7 +109,6 @@ import UIKit
|
|||||||
setupView()
|
setupView()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Basic initializer.
|
|
||||||
public convenience init() {
|
public convenience init() {
|
||||||
self.init(frame: .zero)
|
self.init(frame: .zero)
|
||||||
}
|
}
|
||||||
@ -120,9 +119,9 @@ import UIKit
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// - parameter bothDelegates: Sets both MF/UI Text Field Delegates.
|
/// - parameter bothDelegates: Sets both MF/UI Text Field Delegates.
|
||||||
public init(bothDelegates: (UITextFieldDelegate & TextFieldDelegate)?) {
|
public convenience init(bothDelegates: (UITextFieldDelegate & TextFieldDelegate)?) {
|
||||||
super.init(frame: .zero)
|
self.init(frame: .zero)
|
||||||
setupView()
|
|
||||||
setBothTextDelegates(bothDelegates)
|
setBothTextDelegates(bothDelegates)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -174,7 +173,7 @@ import UIKit
|
|||||||
|
|
||||||
open func clearError() {
|
open func clearError() {
|
||||||
|
|
||||||
// feedback = nil
|
feedback = nil
|
||||||
textField?.accessibilityValue = nil
|
textField?.accessibilityValue = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -192,7 +191,7 @@ import UIKit
|
|||||||
}
|
}
|
||||||
|
|
||||||
@objc func dismissTextFieldResponder(_ sender: Any?) {
|
@objc func dismissTextFieldResponder(_ sender: Any?) {
|
||||||
originalAppearance()
|
|
||||||
textField?.resignFirstResponder()
|
textField?.resignFirstResponder()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -200,7 +199,7 @@ import UIKit
|
|||||||
// MARK: - Observing for change
|
// MARK: - Observing for change
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
|
|
||||||
func valueChanged() {
|
@objc func valueChanged() {
|
||||||
|
|
||||||
if !showErrorMessage {
|
if !showErrorMessage {
|
||||||
feedback = ""
|
feedback = ""
|
||||||
@ -224,19 +223,19 @@ import UIKit
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func endInputing() {
|
@objc func endInputing() {
|
||||||
|
|
||||||
if isValid {
|
if isValid {
|
||||||
clearError()
|
clearError()
|
||||||
bottomBar.backgroundColor = UIColor.black.cgColor
|
bottomBar.backgroundColor = UIColor.black.cgColor
|
||||||
|
|
||||||
} else if let errMessage = errorMessage {
|
} else if let errMessage = errorMessage {
|
||||||
feedback = errMessage
|
feedback = errMessage
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func startEditing() {
|
@objc func startEditing() {
|
||||||
|
|
||||||
errorAppearance(showError: true)
|
|
||||||
textField?.becomeFirstResponder()
|
textField?.becomeFirstResponder()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user