Commit 13c7ebda by Zennon Gosalvez

Added customising bottom border colors.

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