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 {
}
private func prepareNameField() {
let d: CGFloat = 40
nameField = TextField()
nameField.text = "Daniel Dahan"
nameField.placeholder = "Name"
......@@ -77,16 +79,26 @@ class ViewController: UIViewController {
// Size the TextField to the maximum width, less 40 pixels on either side
// 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() {
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.detail = "Error, incorrect email"
emailField.isClearIconButtonEnabled = true
emailField.delegate = self
emailField.leftView = leftView
emailField.leftViewMode = .always
emailField.divider.contentEdgeInsets.left = d
emailField.placeholderNormalColor = Color.amber.darken4
emailField.placeholderActiveColor = Color.pink.base
emailField.dividerNormalColor = Color.cyan.base
......@@ -95,6 +107,8 @@ class ViewController: UIViewController {
}
private func preparePasswordField() {
let d: CGFloat = 40
passwordField = TextField()
passwordField.placeholder = "Password"
passwordField.detail = "At least 8 characters"
......@@ -106,7 +120,7 @@ class ViewController: UIViewController {
// Size the TextField to the maximum width, less 40 pixels on either side
// 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 {
internal var line: UIView?
/// 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.
open var color: UIColor? {
......@@ -91,15 +105,17 @@ open class Divider {
return
}
let c = contentEdgeInsets
switch alignment {
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:
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:
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:
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,11 +437,11 @@ open class TextField: UITextField {
/// Layout the placeholderLabel.
open func layoutPlaceholderLabel() {
if !isEditing && true == text?.isEmpty && isPlaceholderAnimated {
if let leftViewWidth = self.leftView?.frame.size.width {
placeholderLabel.frame = CGRect(x: leftViewWidth, y: bounds.origin.y, width: bounds.size.width - leftViewWidth, height: bounds.size.height)
} else {
placeholderLabel.frame = bounds
}
if let v = leftView?.width {
placeholderLabel.frame = CGRect(x: v, y: bounds.origin.y, width: bounds.width - v, height: bounds.height)
} else {
placeholderLabel.frame = bounds
}
} else if placeholderLabel.transform.isIdentity {
placeholderLabel.frame = bounds
placeholderLabel.transform = CGAffineTransform(scaleX: 0.75, y: 0.75)
......@@ -549,7 +549,7 @@ open class TextField: UITextField {
}
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.textColor = s.placeholderNormalColor
}) { [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