Commit 0881e196 by Alessandro Nakamuta

Added custom placeholderPadding and detailDistance

Added custom placeholder padding and custom detail Distance to divider. The default values is to high for me.
parent e577cfa3
...@@ -49,6 +49,11 @@ public class TextField : UITextField { ...@@ -49,6 +49,11 @@ public class TextField : UITextField {
layer.masksToBounds = value layer.masksToBounds = value
} }
} }
/**
This property adds a padding to placeholder y position animation
*/
public var placeholderAnimationPadding: CGFloat = 0
/// A property that accesses the backing layer's backgroundColor. /// A property that accesses the backing layer's backgroundColor.
@IBInspectable public override var backgroundColor: UIColor? { @IBInspectable public override var backgroundColor: UIColor? {
...@@ -227,6 +232,9 @@ public class TextField : UITextField { ...@@ -227,6 +232,9 @@ public class TextField : UITextField {
} }
} }
} }
/// Vertical distance of detail label to divider
public var detailDistance: CGFloat = 8
/// Handles the textAlignment of the placeholderLabel. /// Handles the textAlignment of the placeholderLabel.
public override var textAlignment: NSTextAlignment { public override var textAlignment: NSTextAlignment {
...@@ -513,7 +521,7 @@ public class TextField : UITextField { ...@@ -513,7 +521,7 @@ public class TextField : UITextField {
/// Layout the detailLabel. /// Layout the detailLabel.
public func layoutDetailLabel() { public func layoutDetailLabel() {
let h: CGFloat = nil == detail ? 12 : detailLabel.font.stringSize(detail!, constrainedToWidth: Double(width)).height let h: CGFloat = nil == detail ? 12 : detailLabel.font.stringSize(detail!, constrainedToWidth: Double(width)).height
detailLabel.frame = CGRectMake(0, divider.frame.origin.y + 8, width, h) detailLabel.frame = CGRectMake(0, divider.frame.origin.y + detailDistance, width, h)
} }
/// Layout the clearIconButton. /// Layout the clearIconButton.
...@@ -560,7 +568,7 @@ public class TextField : UITextField { ...@@ -560,7 +568,7 @@ public class TextField : UITextField {
v.placeholderLabel.frame.origin.x = v.width - v.placeholderLabel.frame.width v.placeholderLabel.frame.origin.x = v.width - v.placeholderLabel.frame.width
default:break default:break
} }
v.placeholderLabel.frame.origin.y = -v.placeholderLabel.frame.size.height v.placeholderLabel.frame.origin.y = -v.placeholderLabel.frame.size.height + v.placeholderAnimationPadding
v.placeholderLabel.textColor = v.placeholderActiveColor v.placeholderLabel.textColor = v.placeholderActiveColor
} }
}) { [weak self] _ in }) { [weak self] _ in
...@@ -614,4 +622,4 @@ public class TextField : UITextField { ...@@ -614,4 +622,4 @@ public class TextField : UITextField {
addTarget(self, action: #selector(handleEditingDidBegin), forControlEvents: .EditingDidBegin) addTarget(self, action: #selector(handleEditingDidBegin), forControlEvents: .EditingDidBegin)
addTarget(self, action: #selector(handleEditingDidEnd), forControlEvents: .EditingDidEnd) addTarget(self, action: #selector(handleEditingDidEnd), forControlEvents: .EditingDidEnd)
} }
} }
\ No newline at end of file
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