Commit 72c27d79 by Daniel Dahan

Merge pull request #246 from zgosalvez/development

Added customising bottom border colors.
parents f627f85b 13c7ebda
......@@ -301,6 +301,32 @@ public class TextField : UITextField {
*/
@IBInspectable public var bottomBorderLayerDistance: CGFloat = 4
/// The color of the bottomBorderLayer when the textField is not active.
@IBInspectable public var bottomBorderColor: UIColor? {
didSet {
MaterialAnimation.animationDisabled { [unowned self] in
self.bottomBorderLayer.backgroundColor = self.bottomBorderColor?.CGColor
}
}
}
/// The color of the bottomBorderLayer when the textField is active.
@IBInspectable public var bottomBorderTitleActiveColor: UIColor?
/**
The color of the bottomBorderLayer when the detailLabelHidden property is
set to false.
*/
@IBInspectable public var bottomBorderDetailActiveColor: UIColor? {
didSet {
if !detailLabelHidden {
MaterialAnimation.animationDisabled { [unowned self] in
self.bottomBorderLayer.backgroundColor = self.bottomBorderDetailActiveColor?.CGColor
}
}
}
}
/**
The title UILabel that is displayed when there is text. The
titleLabel text value is updated with the placeholder text
......@@ -317,10 +343,12 @@ public class TextField : UITextField {
didSet {
titleLabel?.textColor = titleLabelColor
MaterialAnimation.animationDisabled { [unowned self] in
if nil != self.bottomBorderTitleActiveColor {
self.bottomBorderLayer.backgroundColor = self.titleLabelColor?.CGColor
}
}
}
}
/// The color of the titleLabel text when the textField is active.
@IBInspectable public var titleLabelActiveColor: UIColor?
......@@ -357,11 +385,13 @@ public class TextField : UITextField {
if !detailLabelHidden {
detailLabel?.textColor = detailLabelActiveColor
MaterialAnimation.animationDisabled { [unowned self] in
if nil != self.bottomBorderDetailActiveColor {
self.bottomBorderLayer.backgroundColor = self.detailLabelActiveColor?.CGColor
}
}
}
}
}
/**
A property that sets the distance between the textField and
......@@ -383,13 +413,30 @@ public class TextField : UITextField {
if detailLabelHidden {
detailLabel?.textColor = titleLabelColor
MaterialAnimation.animationDisabled { [unowned self] in
self.bottomBorderLayer.backgroundColor = self.editing ? self.titleLabelActiveColor?.CGColor : self.titleLabelColor?.CGColor
var activeColor: CGColor? = self.titleLabelActiveColor?.CGColor
var inactiveColor: CGColor? = self.titleLabelColor?.CGColor
if let bottomBorderColor: CGColor = self.bottomBorderTitleActiveColor?.CGColor {
activeColor = bottomBorderColor
}
if let bottomBorderColor: CGColor = self.bottomBorderColor?.CGColor {
inactiveColor = bottomBorderColor
}
self.bottomBorderLayer.backgroundColor = self.editing ? activeColor : inactiveColor
}
hideDetailLabel()
} else {
detailLabel?.textColor = detailLabelActiveColor
MaterialAnimation.animationDisabled { [unowned self] in
self.bottomBorderLayer.backgroundColor = self.detailLabelActiveColor?.CGColor
var activeColor: CGColor? = self.detailLabelActiveColor?.CGColor
if let bottomBorderColor: CGColor = self.bottomBorderDetailActiveColor?.CGColor {
activeColor = bottomBorderColor
}
self.bottomBorderLayer.backgroundColor = activeColor
}
showDetailLabel()
}
......@@ -536,7 +583,13 @@ public class TextField : UITextField {
if detailLabelAutoHideEnabled && !detailLabelHidden {
detailLabelHidden = true
MaterialAnimation.animationDisabled { [unowned self] in
self.bottomBorderLayer.backgroundColor = self.titleLabelActiveColor?.CGColor
var activeColor: CGColor? = self.titleLabelActiveColor?.CGColor
if let bottomBorderColor: CGColor = self.bottomBorderTitleActiveColor?.CGColor {
activeColor = bottomBorderColor
}
self.bottomBorderLayer.backgroundColor = activeColor
}
}
}
......@@ -545,9 +598,21 @@ public class TextField : UITextField {
internal func textFieldDidBegin() {
titleLabel?.textColor = titleLabelActiveColor
MaterialAnimation.animationDisabled { [unowned self] in
self.bottomBorderLayer.backgroundColor = self.detailLabelHidden ? self.titleLabelActiveColor?.CGColor : self.detailLabelActiveColor?.CGColor
var titleActiveColor: CGColor? = self.titleLabelActiveColor?.CGColor
var detailActiveColor: CGColor? = self.detailLabelActiveColor?.CGColor
if let bottomBorderColor: CGColor = self.bottomBorderTitleActiveColor?.CGColor {
titleActiveColor = bottomBorderColor
}
if let bottomBorderColor: CGColor = self.bottomBorderDetailActiveColor?.CGColor {
detailActiveColor = bottomBorderColor
}
self.bottomBorderLayer.backgroundColor = self.detailLabelHidden ? titleActiveColor : detailActiveColor
}
}
/// Handler for text changed.
internal func textFieldDidChange() {
......@@ -568,7 +633,18 @@ public class TextField : UITextField {
}
titleLabel?.textColor = titleLabelColor
MaterialAnimation.animationDisabled { [unowned self] in
self.bottomBorderLayer.backgroundColor = self.detailLabelHidden ? self.titleLabelColor?.CGColor : self.detailLabelActiveColor?.CGColor
var borderColor: CGColor? = self.titleLabelColor?.CGColor
var detailActiveColor: CGColor? = self.detailLabelActiveColor?.CGColor
if let bottomBorderColor: CGColor = self.bottomBorderColor?.CGColor {
borderColor = bottomBorderColor
}
if let bottomBorderColor: CGColor = self.bottomBorderDetailActiveColor?.CGColor {
detailActiveColor = bottomBorderColor
}
self.bottomBorderLayer.backgroundColor = self.detailLabelHidden ? borderColor : detailActiveColor
}
}
......
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