latest, updating.
This commit is contained in:
parent
1d08842d47
commit
df34e1574c
@ -18,8 +18,11 @@ import UIKit
|
|||||||
// MARK: - Outlets
|
// MARK: - Outlets
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
|
|
||||||
let digitField: UITextField = {
|
let digitField: TextField = {
|
||||||
let textField = UITextField(frame: .zero)
|
let textField = TextField()
|
||||||
|
textField.isAccessibilityElement = true
|
||||||
|
textField.setContentCompressionResistancePriority(.required, for: .vertical)
|
||||||
|
textField.setContentCompressionResistancePriority(.required, for: .horizontal)
|
||||||
textField.textAlignment = .center
|
textField.textAlignment = .center
|
||||||
textField.keyboardType = .numberPad
|
textField.keyboardType = .numberPad
|
||||||
return textField
|
return textField
|
||||||
@ -31,6 +34,27 @@ import UIKit
|
|||||||
|
|
||||||
private var previousSize: CGFloat = 0.0
|
private var previousSize: CGFloat = 0.0
|
||||||
|
|
||||||
|
//--------------------------------------------------
|
||||||
|
// MARK: - Property Observer
|
||||||
|
//--------------------------------------------------
|
||||||
|
|
||||||
|
public override var showError: Bool {
|
||||||
|
didSet {
|
||||||
|
DispatchQueue.main.async { [weak self] in
|
||||||
|
guard let self = self else { return }
|
||||||
|
|
||||||
|
self.borderStrokeColor = self.showError ? .mfPumpkin() : .mfSilver()
|
||||||
|
|
||||||
|
let barHeight: CGFloat = self.showError ? 4 : 1
|
||||||
|
self.bottomBar.frame = CGRect(x: 0, y: self.bounds.height - barHeight, width: self.bounds.width, height: barHeight)
|
||||||
|
self.bottomBar.backgroundColor = self.showError ? UIColor.mfPumpkin().cgColor : UIColor.black.cgColor
|
||||||
|
|
||||||
|
self.setNeedsDisplay()
|
||||||
|
self.layoutIfNeeded()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Delegate
|
// MARK: - Delegate
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
@ -59,7 +83,7 @@ import UIKit
|
|||||||
|
|
||||||
required public init?(coder: NSCoder) {
|
required public init?(coder: NSCoder) {
|
||||||
super.init(coder: coder)
|
super.init(coder: coder)
|
||||||
fatalError("DigitBox has not been implemented")
|
fatalError("DigitBox does not support xibs.")
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
@ -72,12 +96,19 @@ import UIKit
|
|||||||
|
|
||||||
translatesAutoresizingMaskIntoConstraints = false
|
translatesAutoresizingMaskIntoConstraints = false
|
||||||
backgroundColor = .white
|
backgroundColor = .white
|
||||||
|
|
||||||
|
addSubview(digitField)
|
||||||
digitField.delegate = self
|
digitField.delegate = self
|
||||||
showErrorState(false)
|
|
||||||
|
NSLayoutConstraint.activate([
|
||||||
|
digitField.heightAnchor.constraint(equalToConstant: 24),
|
||||||
|
digitField.topAnchor.constraint(equalTo: topAnchor, constant: 12),
|
||||||
|
digitField.leadingAnchor.constraint(equalTo: leadingAnchor, constant: 12),
|
||||||
|
bottomAnchor.constraint(equalTo: digitField.bottomAnchor, constant: 12),
|
||||||
|
trailingAnchor.constraint(equalTo: digitField.trailingAnchor, constant: 12)])
|
||||||
|
|
||||||
widthConstraint = widthAnchor.constraint(equalToConstant: 39)
|
widthConstraint = widthAnchor.constraint(equalToConstant: 39)
|
||||||
widthConstraint?.isActive = true
|
widthConstraint?.isActive = true
|
||||||
|
|
||||||
heightConstraint = heightAnchor.constraint(equalToConstant: 44)
|
heightConstraint = heightAnchor.constraint(equalToConstant: 44)
|
||||||
heightConstraint?.isActive = true
|
heightConstraint?.isActive = true
|
||||||
|
|
||||||
@ -96,14 +127,14 @@ import UIKit
|
|||||||
// MARK: - Methods
|
// MARK: - Methods
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
|
|
||||||
public func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
|
// public func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
|
||||||
|
//
|
||||||
if string.isBackspace {
|
// if string.isBackspace {
|
||||||
textBoxDelegate?.textFieldDidDelete?(self.digitField)
|
// textBoxDelegate?.textFieldDidDelete?(self.digitField)
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
return true
|
// return true
|
||||||
}
|
// }
|
||||||
|
|
||||||
public override func updateView(_ size: CGFloat) {
|
public override func updateView(_ size: CGFloat) {
|
||||||
super.updateView(size)
|
super.updateView(size)
|
||||||
@ -140,26 +171,14 @@ import UIKit
|
|||||||
self.setNeedsLayout()
|
self.setNeedsLayout()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func showErrorState(_ show: Bool) {
|
|
||||||
|
|
||||||
showError = show
|
|
||||||
borderStrokeColor = show ? .mfPumpkin() : .mfSilver()
|
|
||||||
|
|
||||||
let barHeight: CGFloat = show ? 4 : 1
|
|
||||||
bottomBar.frame = CGRect(x: 0, y: bounds.height - barHeight, width: bounds.width, height: barHeight)
|
|
||||||
bottomBar.backgroundColor = show ? UIColor.mfPumpkin().cgColor : UIColor.black.cgColor
|
|
||||||
|
|
||||||
setNeedsDisplay()
|
|
||||||
layoutIfNeeded()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// TODO: Move if working properly.
|
// TODO: Move if working properly.
|
||||||
extension String {
|
//extension String {
|
||||||
var isBackspace: Bool {
|
//
|
||||||
let char = self.cString(using: String.Encoding.utf8)!
|
// var isBackspace: Bool {
|
||||||
return strcmp(char, "\\b") == -92
|
// let char = self.cString(using: String.Encoding.utf8)!
|
||||||
}
|
// return strcmp(char, "\\b") == -92
|
||||||
}
|
// }
|
||||||
|
//}
|
||||||
|
|||||||
@ -21,6 +21,10 @@ import UIKit
|
|||||||
|
|
||||||
public var digitFields: [DigitBox] = []
|
public var digitFields: [DigitBox] = []
|
||||||
|
|
||||||
|
//--------------------------------------------------
|
||||||
|
// MARK: - Properties
|
||||||
|
//--------------------------------------------------
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Property Observers
|
// MARK: - Property Observers
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
@ -31,7 +35,6 @@ import UIKit
|
|||||||
|
|
||||||
digitFields.forEach {
|
digitFields.forEach {
|
||||||
$0.isEnabled = self.isEnabled
|
$0.isEnabled = self.isEnabled
|
||||||
|
|
||||||
$0.isUserInteractionEnabled = isEnabled
|
$0.isUserInteractionEnabled = isEnabled
|
||||||
$0.digitField.isEnabled = isEnabled
|
$0.digitField.isEnabled = isEnabled
|
||||||
$0.digitField.textColor = isEnabled ? .black : .mfBattleshipGrey()
|
$0.digitField.textColor = isEnabled ? .black : .mfBattleshipGrey()
|
||||||
@ -42,7 +45,6 @@ import UIKit
|
|||||||
public override var placeholder: String? {
|
public override var placeholder: String? {
|
||||||
get {
|
get {
|
||||||
var string = ""
|
var string = ""
|
||||||
|
|
||||||
digitFields.forEach { string += $0.digitField.attributedPlaceholder?.string ?? "" }
|
digitFields.forEach { string += $0.digitField.attributedPlaceholder?.string ?? "" }
|
||||||
|
|
||||||
return !string.isEmpty ? string : nil
|
return !string.isEmpty ? string : nil
|
||||||
@ -78,7 +80,6 @@ import UIKit
|
|||||||
public override var text: String? {
|
public override var text: String? {
|
||||||
get {
|
get {
|
||||||
var string = ""
|
var string = ""
|
||||||
|
|
||||||
digitFields.forEach { string += $0.digitField.text ?? "" }
|
digitFields.forEach { string += $0.digitField.text ?? "" }
|
||||||
|
|
||||||
return string
|
return string
|
||||||
@ -109,9 +110,8 @@ import UIKit
|
|||||||
self.init(frame: .zero)
|
self.init(frame: .zero)
|
||||||
}
|
}
|
||||||
|
|
||||||
public init(numberOfDigits: Int) {
|
public convenience init(numberOfDigits: Int) {
|
||||||
super.init(frame: .zero)
|
self.init(frame: .zero)
|
||||||
|
|
||||||
self.numberOfDigits = numberOfDigits
|
self.numberOfDigits = numberOfDigits
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -133,9 +133,10 @@ import UIKit
|
|||||||
|
|
||||||
alignCenterHorizontal()
|
alignCenterHorizontal()
|
||||||
isAccessibilityElement = false
|
isAccessibilityElement = false
|
||||||
|
entryContainer.hideBorder = true
|
||||||
entryContainer.bottomBar.backgroundColor = UIColor.clear.cgColor
|
entryContainer.bottomBar.backgroundColor = UIColor.clear.cgColor
|
||||||
entryContainer.bottomBar.frame = CGRect(x: 0, y: entryContainer.bounds.height, width: 0, height: 0)
|
entryContainer.bottomBar.frame = CGRect(x: 0, y: entryContainer.bounds.height, width: 0, height: 0)
|
||||||
setupDigitFieldsView(size: MVMCoreUISplitViewController.getDetailViewWidth())
|
assembleDigitFieldsView(size: MVMCoreUISplitViewController.getDetailViewWidth())
|
||||||
|
|
||||||
textField.removeFromSuperview()
|
textField.removeFromSuperview()
|
||||||
}
|
}
|
||||||
@ -149,7 +150,7 @@ import UIKit
|
|||||||
return digitBox
|
return digitBox
|
||||||
}
|
}
|
||||||
|
|
||||||
func setupDigitFieldsView(size: CGFloat) {
|
func assembleDigitFieldsView(size: CGFloat) {
|
||||||
|
|
||||||
var accessibleElements: [Any] = [titleLabel]
|
var accessibleElements: [Any] = [titleLabel]
|
||||||
|
|
||||||
@ -166,7 +167,6 @@ import UIKit
|
|||||||
|
|
||||||
box.topAnchor.constraint(equalTo: entryContainer.topAnchor).isActive = true
|
box.topAnchor.constraint(equalTo: entryContainer.topAnchor).isActive = true
|
||||||
entryContainer.bottomAnchor.constraint(equalTo: box.bottomAnchor).isActive = true
|
entryContainer.bottomAnchor.constraint(equalTo: box.bottomAnchor).isActive = true
|
||||||
box.centerYAnchor.constraint(equalTo: entryContainer.centerYAnchor).isActive = true
|
|
||||||
|
|
||||||
if index == 0 {
|
if index == 0 {
|
||||||
box.leadingAnchor.constraint(equalTo: entryContainer.leadingAnchor).isActive = true
|
box.leadingAnchor.constraint(equalTo: entryContainer.leadingAnchor).isActive = true
|
||||||
@ -203,33 +203,13 @@ import UIKit
|
|||||||
self.digitFields.forEach { $0.updateView(size) }
|
self.digitFields.forEach { $0.updateView(size) }
|
||||||
self.layoutIfNeeded()
|
self.layoutIfNeeded()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Layout text boxes.
|
|
||||||
// self.setupDigitFieldsView(size: size)
|
|
||||||
}
|
}
|
||||||
// hideBorder = true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Methods
|
// MARK: - Methods
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
|
|
||||||
override func valueChanged() {
|
|
||||||
super.valueChanged()
|
|
||||||
|
|
||||||
// TODO: is feedbackContainerDistance needed?
|
|
||||||
// DispatchQueue.main.async { [weak self] in
|
|
||||||
// guard let self = self else { return }
|
|
||||||
//
|
|
||||||
// if let feedback = self.feedback, !feedback.isEmpty {
|
|
||||||
// self.feedbackContainerDistance?.constant = 10
|
|
||||||
//
|
|
||||||
// } else {
|
|
||||||
// self.feedbackContainerDistance?.constant = 0
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
|
|
||||||
func setAsSecureTextEntry(_ secureEntry: Bool) {
|
func setAsSecureTextEntry(_ secureEntry: Bool) {
|
||||||
|
|
||||||
DispatchQueue.main.async { [weak self] in
|
DispatchQueue.main.async { [weak self] in
|
||||||
@ -411,7 +391,7 @@ extension DigitEntryField {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
setupDigitFieldsView(size: MVMCoreUIUtility.getWidth())
|
assembleDigitFieldsView(size: MVMCoreUIUtility.getWidth())
|
||||||
}
|
}
|
||||||
|
|
||||||
open override class func estimatedHeight(forRow json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat {
|
open override class func estimatedHeight(forRow json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user