Commit 29c8b327 by Daniel Dahan

development: Updated the TextField example project to reflect PR 544. Added…

development: Updated the TextField example project to reflect PR 544. Added contentEdgeInsets to Divider.
parent 027880ba
...@@ -68,6 +68,8 @@ class ViewController: UIViewController { ...@@ -68,6 +68,8 @@ class ViewController: UIViewController {
} }
private func prepareNameField() { private func prepareNameField() {
let d: CGFloat = 40
nameField = TextField() nameField = TextField()
nameField.text = "Daniel Dahan" nameField.text = "Daniel Dahan"
nameField.placeholder = "Name" nameField.placeholder = "Name"
...@@ -77,16 +79,26 @@ class ViewController: UIViewController { ...@@ -77,16 +79,26 @@ class ViewController: UIViewController {
// Size the TextField to the maximum width, less 40 pixels on either side // Size the TextField to the maximum width, less 40 pixels on either side
// with a top margin of 40 pixels. // with a top margin of 40 pixels.
view.layout(nameField).top(40).horizontally(left: 40, right: 40) view.layout(nameField).top(d).horizontally(left: d, right: d)
} }
private func prepareEmailField() { private func prepareEmailField() {
emailField = ErrorTextField(frame: CGRect(x: 40, y: 120, width: view.width - 80, height: 32)) let d: CGFloat = 32
let leftView = UIImageView(frame: CGRect(x: 0, y: 0, width: d, height: d))
leftView.image = Icon.cm.check?.tint(with: Color.cyan.base)
leftView.contentMode = .center
emailField = ErrorTextField(frame: CGRect(x: 40, y: 120, width: view.width - 80, height: d))
emailField.placeholder = "Email" emailField.placeholder = "Email"
emailField.detail = "Error, incorrect email" emailField.detail = "Error, incorrect email"
emailField.isClearIconButtonEnabled = true emailField.isClearIconButtonEnabled = true
emailField.delegate = self emailField.delegate = self
emailField.leftView = leftView
emailField.leftViewMode = .always
emailField.divider.contentEdgeInsets.left = d
emailField.placeholderNormalColor = Color.amber.darken4 emailField.placeholderNormalColor = Color.amber.darken4
emailField.placeholderActiveColor = Color.pink.base emailField.placeholderActiveColor = Color.pink.base
emailField.dividerNormalColor = Color.cyan.base emailField.dividerNormalColor = Color.cyan.base
...@@ -95,6 +107,8 @@ class ViewController: UIViewController { ...@@ -95,6 +107,8 @@ class ViewController: UIViewController {
} }
private func preparePasswordField() { private func preparePasswordField() {
let d: CGFloat = 40
passwordField = TextField() passwordField = TextField()
passwordField.placeholder = "Password" passwordField.placeholder = "Password"
passwordField.detail = "At least 8 characters" passwordField.detail = "At least 8 characters"
...@@ -106,7 +120,7 @@ class ViewController: UIViewController { ...@@ -106,7 +120,7 @@ class ViewController: UIViewController {
// Size the TextField to the maximum width, less 40 pixels on either side // Size the TextField to the maximum width, less 40 pixels on either side
// with a top margin of 200 pixels. // with a top margin of 200 pixels.
view.layout(passwordField).top(200).horizontally(left: 40, right: 40) view.layout(passwordField).top(200).horizontally(left: d, right: d)
} }
} }
......
...@@ -46,7 +46,21 @@ open class Divider { ...@@ -46,7 +46,21 @@ open class Divider {
internal var line: UIView? internal var line: UIView?
/// A reference to the height. /// A reference to the height.
public var height: CGFloat open var height: CGFloat
/// A preset wrapper around contentEdgeInsets.
open var contentEdgeInsetsPreset = EdgeInsetsPreset.none {
didSet {
contentEdgeInsets = EdgeInsetsPresetToValue(preset: contentEdgeInsetsPreset)
}
}
/// A reference to EdgeInsets.
open var contentEdgeInsets = EdgeInsets.zero {
didSet {
reload()
}
}
/// A UIColor. /// A UIColor.
open var color: UIColor? { open var color: UIColor? {
...@@ -91,15 +105,17 @@ open class Divider { ...@@ -91,15 +105,17 @@ open class Divider {
return return
} }
let c = contentEdgeInsets
switch alignment { switch alignment {
case .top: case .top:
l.frame = CGRect(x: 0, y: 0, width: v.width, height: height) l.frame = CGRect(x: c.left, y: c.top, width: v.width - c.left - c.right, height: height - c.top - c.bottom)
case .bottom: case .bottom:
l.frame = CGRect(x: 0, y: v.height - height, width: v.width, height: height) l.frame = CGRect(x: c.left, y: v.height - height - c.bottom, width: v.width - c.left - c.right, height: height - c.top - c.bottom)
case .left: case .left:
l.frame = CGRect(x: 0, y: 0, width: height, height: v.height) l.frame = CGRect(x: c.left, y: c.top, width: height, height: v.height - c.top - c.bottom)
case .right: case .right:
l.frame = CGRect(x: v.width - height, y: 0, width: height, height: v.height) l.frame = CGRect(x: v.width - height - c.right, y: c.top, width: height, height: v.height - c.top - c.bottom)
} }
} }
} }
......
...@@ -437,8 +437,8 @@ open class TextField: UITextField { ...@@ -437,8 +437,8 @@ open class TextField: UITextField {
/// Layout the placeholderLabel. /// Layout the placeholderLabel.
open func layoutPlaceholderLabel() { open func layoutPlaceholderLabel() {
if !isEditing && true == text?.isEmpty && isPlaceholderAnimated { if !isEditing && true == text?.isEmpty && isPlaceholderAnimated {
if let leftViewWidth = self.leftView?.frame.size.width { if let v = leftView?.width {
placeholderLabel.frame = CGRect(x: leftViewWidth, y: bounds.origin.y, width: bounds.size.width - leftViewWidth, height: bounds.size.height) placeholderLabel.frame = CGRect(x: v, y: bounds.origin.y, width: bounds.width - v, height: bounds.height)
} else { } else {
placeholderLabel.frame = bounds placeholderLabel.frame = bounds
} }
...@@ -549,7 +549,7 @@ open class TextField: UITextField { ...@@ -549,7 +549,7 @@ open class TextField: UITextField {
} }
s.placeholderLabel.transform = CGAffineTransform.identity s.placeholderLabel.transform = CGAffineTransform.identity
s.placeholderLabel.x = s.leftView?.frame.size.width ?? 0 s.placeholderLabel.x = s.leftView?.width ?? 0
s.placeholderLabel.y = 0 s.placeholderLabel.y = 0
s.placeholderLabel.textColor = s.placeholderNormalColor s.placeholderLabel.textColor = s.placeholderNormalColor
}) { [weak self] _ in }) { [weak self] _ in
......
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