Commit c06092a1 by Daniel Dahan

development: progression with TextField

parent 1ace72ee
...@@ -46,11 +46,12 @@ class ViewController: UIViewController { ...@@ -46,11 +46,12 @@ class ViewController: UIViewController {
prepareNameField() prepareNameField()
prepareEmailField() prepareEmailField()
preparePasswordField() preparePasswordField()
prepareResignResponderButton()
} }
/// Programmatic update for the textField as it rotates. /// Programmatic update for the textField as it rotates.
override func willRotate(to toInterfaceOrientation: UIInterfaceOrientation, duration: TimeInterval) { override func willRotate(to toInterfaceOrientation: UIInterfaceOrientation, duration: TimeInterval) {
emailField.width = (Device.isLandscape ? view.height : view.width) - 2 * constant emailField.width = view.height - 2 * constant
} }
/// Prepares the resign responder button. /// Prepares the resign responder button.
...@@ -83,8 +84,6 @@ class ViewController: UIViewController { ...@@ -83,8 +84,6 @@ class ViewController: UIViewController {
nameField.leftView = leftView nameField.leftView = leftView
nameField.leftViewMode = .always nameField.leftViewMode = .always
nameField.placeholderLabel.backgroundColor = Color.green.base
view.layout(nameField).top(4 * constant).horizontally(left: constant, right: constant) view.layout(nameField).top(4 * constant).horizontally(left: constant, right: constant)
} }
...@@ -103,8 +102,6 @@ class ViewController: UIViewController { ...@@ -103,8 +102,6 @@ class ViewController: UIViewController {
emailField.leftView = leftView emailField.leftView = leftView
emailField.leftViewMode = .always emailField.leftViewMode = .always
emailField.placeholderLabel.backgroundColor = Color.green.base
// Set the colors for the emailField, different from the defaults. // Set the colors for the emailField, different from the defaults.
// emailField.placeholderNormalColor = Color.amber.darken4 // emailField.placeholderNormalColor = Color.amber.darken4
// emailField.placeholderActiveColor = Color.pink.base // emailField.placeholderActiveColor = Color.pink.base
...@@ -124,8 +121,6 @@ class ViewController: UIViewController { ...@@ -124,8 +121,6 @@ class ViewController: UIViewController {
// Setting the visibilityIconButton color. // Setting the visibilityIconButton color.
passwordField.visibilityIconButton?.tintColor = Color.green.base.withAlphaComponent(passwordField.isSecureTextEntry ? 0.38 : 0.54) passwordField.visibilityIconButton?.tintColor = Color.green.base.withAlphaComponent(passwordField.isSecureTextEntry ? 0.38 : 0.54)
passwordField.placeholderLabel.backgroundColor = Color.green.base
view.layout(passwordField).top(10 * constant).horizontally(left: constant, right: constant) view.layout(passwordField).top(10 * constant).horizontally(left: constant, right: constant)
} }
} }
......
...@@ -74,6 +74,7 @@ open class TextField: UITextField { ...@@ -74,6 +74,7 @@ open class TextField: UITextField {
open override var leftView: UIView? { open override var leftView: UIView? {
didSet { didSet {
prepareLeftView()
layoutSubviews() layoutSubviews()
} }
} }
...@@ -365,9 +366,6 @@ open class TextField: UITextField { ...@@ -365,9 +366,6 @@ open class TextField: UITextField {
open override func layoutSubviews() { open override func layoutSubviews() {
super.layoutSubviews() super.layoutSubviews()
layoutDivider()
layoutLeftView()
reload() reload()
} }
...@@ -458,43 +456,33 @@ open class TextField: UITextField { ...@@ -458,43 +456,33 @@ open class TextField: UITextField {
layoutDetailLabel() layoutDetailLabel()
layoutButton(button: clearIconButton) layoutButton(button: clearIconButton)
layoutButton(button: visibilityIconButton) layoutButton(button: visibilityIconButton)
layoutDivider()
layoutLeftView()
} }
/// Layout the divider.
open func layoutDivider() {
divider.reload()
}
/// Layout the placeholderLabel. /// Layout the placeholderLabel.
open func layoutPlaceholderLabel() { open func layoutPlaceholderLabel() {
let w = leftViewWidth let w = leftViewWidth
let h = 0 == height ? intrinsicContentSize.height : height let h = 0 == height ? intrinsicContentSize.height : height
if !isEditing && true == text?.isEmpty && isPlaceholderAnimated { guard isEditing || false == text?.isEmpty || !isPlaceholderAnimated else {
placeholderLabel.frame = CGRect(x: w, y: 0, width: width - w, height: h) placeholderLabel.frame = CGRect(x: w, y: 0, width: width - w, height: h)
} else if placeholderLabel.transform.isIdentity { return
placeholderLabel.frame = CGRect(x: w, y: 0, width: width - w, height: h) }
placeholderLabel.transform = CGAffineTransform(scaleX: 0.75, y: 0.75)
switch textAlignment { placeholderLabel.transform = CGAffineTransform.identity
case .left, .natural: placeholderLabel.frame = CGRect(x: w, y: 0, width: width - w, height: h)
placeholderLabel.x = w placeholderLabel.transform = CGAffineTransform(scaleX: 0.75, y: 0.75)
case .right:
placeholderLabel.x = width - placeholderLabel.width switch textAlignment {
default:break case .left, .natural:
} placeholderLabel.x = w
placeholderLabel.y = -placeholderLabel.height + placeholderVerticalOffset case .right:
} else { placeholderLabel.x = width - placeholderLabel.width
switch textAlignment { default:break
case .left, .natural: }
placeholderLabel.x = w
case .right: placeholderLabel.y = -placeholderLabel.height + placeholderVerticalOffset
placeholderLabel.x = width - placeholderLabel.width
case .center:
placeholderLabel.center.x = (width + w) / 2
default:break
}
placeholderLabel.width = (width - w) * 0.75
}
} }
/// Layout the detailLabel. /// Layout the detailLabel.
...@@ -515,6 +503,11 @@ open class TextField: UITextField { ...@@ -515,6 +503,11 @@ open class TextField: UITextField {
button?.frame = CGRect(x: width - height, y: 0, width: height, height: height) button?.frame = CGRect(x: width - height, y: 0, width: height, height: height)
} }
/// Layout the divider.
open func layoutDivider() {
divider.reload()
}
/// Layout the leftView. /// Layout the leftView.
open func layoutLeftView() { open func layoutLeftView() {
guard let v = leftView else { guard let v = leftView else {
...@@ -522,11 +515,7 @@ open class TextField: UITextField { ...@@ -522,11 +515,7 @@ open class TextField: UITextField {
} }
let w = leftViewWidth let w = leftViewWidth
v.frame = CGRect(x: 0, y: 0, width: w, height: height)
v.width = w
v.height = height
v.contentMode = .center
divider.contentEdgeInsets.left = w divider.contentEdgeInsets.left = w
} }
...@@ -622,6 +611,11 @@ open class TextField: UITextField { ...@@ -622,6 +611,11 @@ open class TextField: UITextField {
addSubview(detailLabel) addSubview(detailLabel)
addObserver(self, forKeyPath: "detailLabel.text", options: [], context: &TextFieldContext) addObserver(self, forKeyPath: "detailLabel.text", options: [], context: &TextFieldContext)
} }
/// Prepares the leftView.
private func prepareLeftView() {
leftView?.contentMode = .center
}
/// Prepares the target handlers. /// Prepares the target handlers.
private func prepareTargetHandlers() { private func prepareTargetHandlers() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment