Commit 9b743d59 by Michael Gaylord

Make it compile

parent 361b858d
...@@ -45,7 +45,7 @@ public protocol TextFieldDelegate: UITextFieldDelegate { ...@@ -45,7 +45,7 @@ public protocol TextFieldDelegate: UITextFieldDelegate {
*/ */
@objc @objc
optional func textField(textField: UITextField, didChange text: String?) optional func textField(textField: UITextField, didChange text: String?)
/** /**
A delegation method that is executed when the textField will clear. A delegation method that is executed when the textField will clear.
- Parameter textField: A UITextField. - Parameter textField: A UITextField.
...@@ -133,8 +133,8 @@ open class TextField: UITextField { ...@@ -133,8 +133,8 @@ open class TextField: UITextField {
} }
/// Divider active height. /// Divider active height.
@IBInspectable @IBInspectable
open var dividerActiveHeight: CGFloat = 2 { open var dividerActiveHeight: CGFloat = 2 {
didSet { didSet {
guard isEditing else { guard isEditing else {
...@@ -144,9 +144,9 @@ open class TextField: UITextField { ...@@ -144,9 +144,9 @@ open class TextField: UITextField {
dividerThickness = dividerActiveHeight dividerThickness = dividerActiveHeight
} }
} }
/// Divider normal color. /// Divider normal color.
@IBInspectable @IBInspectable
open var dividerNormalColor = Color.darkText.dividers { open var dividerNormalColor = Color.darkText.dividers {
didSet { didSet {
guard !isEditing else { guard !isEditing else {
...@@ -156,121 +156,121 @@ open class TextField: UITextField { ...@@ -156,121 +156,121 @@ open class TextField: UITextField {
dividerColor = dividerNormalColor dividerColor = dividerNormalColor
} }
} }
/// Divider active color. /// Divider active color.
@IBInspectable @IBInspectable
open var dividerActiveColor = Color.blue.base { open var dividerActiveColor = Color.blue.base {
didSet { didSet {
guard isEditing else { guard isEditing else {
return return
} }
dividerColor = dividerActiveColor dividerColor = dividerActiveColor
} }
} }
/// The placeholderLabel font value. /// The placeholderLabel font value.
@IBInspectable @IBInspectable
open override var font: UIFont? { open override var font: UIFont? {
didSet { didSet {
placeholderLabel.font = font placeholderLabel.font = font
} }
} }
/// The placeholderLabel text value. /// The placeholderLabel text value.
@IBInspectable @IBInspectable
open override var placeholder: String? { open override var placeholder: String? {
get { get {
return placeholderLabel.text return placeholderLabel.text
} }
set(value) { set(value) {
if isEditing && isPlaceholderUppercasedWhenEditing { if isEditing && isPlaceholderUppercasedWhenEditing {
placeholderLabel.text = value?.uppercased() placeholderLabel.text = value?.uppercased()
} else { } else {
placeholderLabel.text = value placeholderLabel.text = value
} }
layoutSubviews() layoutSubviews()
} }
} }
/// The placeholder UILabel. /// The placeholder UILabel.
@IBInspectable @IBInspectable
open let placeholderLabel = UILabel() open let placeholderLabel = UILabel()
/// Placeholder normal text /// Placeholder normal text
@IBInspectable @IBInspectable
open var placeholderNormalColor = Color.darkText.others { open var placeholderNormalColor = Color.darkText.others {
didSet { didSet {
updatePlaceholderLabelColor() updatePlaceholderLabelColor()
} }
} }
/// Placeholder active text /// Placeholder active text
@IBInspectable @IBInspectable
open var placeholderActiveColor = Color.blue.base { open var placeholderActiveColor = Color.blue.base {
didSet { didSet {
updatePlaceholderLabelColor() updatePlaceholderLabelColor()
} }
} }
/// This property adds a padding to placeholder y position animation /// This property adds a padding to placeholder y position animation
@IBInspectable @IBInspectable
open var placeholderVerticalOffset: CGFloat = 0 open var placeholderVerticalOffset: CGFloat = 0
/// The detailLabel UILabel that is displayed. /// The detailLabel UILabel that is displayed.
@IBInspectable @IBInspectable
open let detailLabel = UILabel() open let detailLabel = UILabel()
/// The detailLabel text value. /// The detailLabel text value.
@IBInspectable @IBInspectable
open var detail: String? { open var detail: String? {
get { get {
return detailLabel.text return detailLabel.text
} }
set(value) { set(value) {
detailLabel.text = value detailLabel.text = value
layoutSubviews() layoutSubviews()
} }
} }
/// Detail text /// Detail text
@IBInspectable @IBInspectable
open var detailColor = Color.darkText.others { open var detailColor = Color.darkText.others {
didSet { didSet {
updateDetailLabelColor() updateDetailLabelColor()
} }
} }
/// Vertical distance for the detailLabel from the divider. /// Vertical distance for the detailLabel from the divider.
@IBInspectable @IBInspectable
open var detailVerticalOffset: CGFloat = 8 { open var detailVerticalOffset: CGFloat = 8 {
didSet { didSet {
layoutDetailLabel() layoutDetailLabel()
} }
} }
/// Handles the textAlignment of the placeholderLabel. /// Handles the textAlignment of the placeholderLabel.
open override var textAlignment: NSTextAlignment { open override var textAlignment: NSTextAlignment {
get { get {
return super.textAlignment return super.textAlignment
} }
set(value) { set(value) {
super.textAlignment = value super.textAlignment = value
placeholderLabel.textAlignment = value placeholderLabel.textAlignment = value
detailLabel.textAlignment = value detailLabel.textAlignment = value
} }
} }
/// A reference to the clearIconButton. /// A reference to the clearIconButton.
open fileprivate(set) var clearIconButton: IconButton? open fileprivate(set) var clearIconButton: IconButton?
/// Enables the clearIconButton. /// Enables the clearIconButton.
@IBInspectable @IBInspectable
open var isClearIconButtonEnabled: Bool { open var isClearIconButtonEnabled: Bool {
get { get {
return nil != clearIconButton return nil != clearIconButton
} }
set(value) { set(value) {
guard value else { guard value else {
clearIconButton?.removeTarget(self, action: #selector(handleClearIconButton), for: .touchUpInside) clearIconButton?.removeTarget(self, action: #selector(handleClearIconButton), for: .touchUpInside)
clearIconButton = nil clearIconButton = nil
...@@ -290,33 +290,33 @@ open class TextField: UITextField { ...@@ -290,33 +290,33 @@ open class TextField: UITextField {
isClearIconButtonAutoHandled = isClearIconButtonAutoHandled ? true : false isClearIconButtonAutoHandled = isClearIconButtonAutoHandled ? true : false
layoutSubviews() layoutSubviews()
} }
} }
/// Enables the automatic handling of the clearIconButton. /// Enables the automatic handling of the clearIconButton.
@IBInspectable @IBInspectable
open var isClearIconButtonAutoHandled = true { open var isClearIconButtonAutoHandled = true {
didSet { didSet {
clearIconButton?.removeTarget(self, action: #selector(handleClearIconButton), for: .touchUpInside) clearIconButton?.removeTarget(self, action: #selector(handleClearIconButton), for: .touchUpInside)
guard isClearIconButtonAutoHandled else { guard isClearIconButtonAutoHandled else {
return return
} }
clearIconButton?.addTarget(self, action: #selector(handleClearIconButton), for: .touchUpInside) clearIconButton?.addTarget(self, action: #selector(handleClearIconButton), for: .touchUpInside)
} }
} }
/// A reference to the visibilityIconButton. /// A reference to the visibilityIconButton.
open fileprivate(set) var visibilityIconButton: IconButton? open fileprivate(set) var visibilityIconButton: IconButton?
/// Enables the visibilityIconButton. /// Enables the visibilityIconButton.
@IBInspectable @IBInspectable
open var isVisibilityIconButtonEnabled: Bool { open var isVisibilityIconButtonEnabled: Bool {
get { get {
return nil != visibilityIconButton return nil != visibilityIconButton
} }
set(value) { set(value) {
guard value else { guard value else {
visibilityIconButton?.removeTarget(self, action: #selector(handleVisibilityIconButton), for: .touchUpInside) visibilityIconButton?.removeTarget(self, action: #selector(handleVisibilityIconButton), for: .touchUpInside)
visibilityIconButton = nil visibilityIconButton = nil
...@@ -337,22 +337,22 @@ open class TextField: UITextField { ...@@ -337,22 +337,22 @@ open class TextField: UITextField {
isVisibilityIconButtonAutoHandled = isVisibilityIconButtonAutoHandled ? true : false isVisibilityIconButtonAutoHandled = isVisibilityIconButtonAutoHandled ? true : false
layoutSubviews() layoutSubviews()
} }
} }
/// Enables the automatic handling of the visibilityIconButton. /// Enables the automatic handling of the visibilityIconButton.
@IBInspectable @IBInspectable
open var isVisibilityIconButtonAutoHandled: Bool = true { open var isVisibilityIconButtonAutoHandled: Bool = true {
didSet { didSet {
visibilityIconButton?.removeTarget(self, action: #selector(handleVisibilityIconButton), for: .touchUpInside) visibilityIconButton?.removeTarget(self, action: #selector(handleVisibilityIconButton), for: .touchUpInside)
guard isVisibilityIconButtonAutoHandled else { guard isVisibilityIconButtonAutoHandled else {
return return
} }
visibilityIconButton?.addTarget(self, action: #selector(handleVisibilityIconButton), for: .touchUpInside) visibilityIconButton?.addTarget(self, action: #selector(handleVisibilityIconButton), for: .touchUpInside)
} }
} }
@IBInspectable @IBInspectable
open var isPlaceholderUppercasedWhenEditing: Bool = false { open var isPlaceholderUppercasedWhenEditing: Bool = false {
...@@ -360,38 +360,38 @@ open class TextField: UITextField { ...@@ -360,38 +360,38 @@ open class TextField: UITextField {
placeholder = placeholder?.uppercased() placeholder = placeholder?.uppercased()
} }
} }
/** /**
An initializer that initializes the object with a NSCoder object. An initializer that initializes the object with a NSCoder object.
- Parameter aDecoder: A NSCoder instance. - Parameter aDecoder: A NSCoder instance.
*/ */
public required init?(coder aDecoder: NSCoder) { public required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder) super.init(coder: aDecoder)
prepare() prepare()
} }
/** /**
An initializer that initializes the object with a CGRect object. An initializer that initializes the object with a CGRect object.
If AutoLayout is used, it is better to initilize the instance If AutoLayout is used, it is better to initilize the instance
using the init() initializer. using the init() initializer.
- Parameter frame: A CGRect instance. - Parameter frame: A CGRect instance.
*/ */
public override init(frame: CGRect) { public override init(frame: CGRect) {
super.init(frame: frame) super.init(frame: frame)
prepare() prepare()
} }
/// A convenience initializer. /// A convenience initializer.
public convenience init() { public convenience init() {
self.init(frame: .zero) self.init(frame: .zero)
} }
open override func layoutSubviews() { open override func layoutSubviews() {
super.layoutSubviews() super.layoutSubviews()
layoutShape() layoutShape()
reload() reload()
} }
open override func becomeFirstResponder() -> Bool { open override func becomeFirstResponder() -> Bool {
setNeedsLayout() setNeedsLayout()
layoutIfNeeded() layoutIfNeeded()
...@@ -409,30 +409,30 @@ open class TextField: UITextField { ...@@ -409,30 +409,30 @@ open class TextField: UITextField {
return textRect(forBounds: bounds) return textRect(forBounds: bounds)
} }
/** /**
Prepares the view instance when intialized. When subclassing, Prepares the view instance when intialized. When subclassing,
it is recommended to override the prepare method it is recommended to override the prepare method
to initialize property values and other setup operations. to initialize property values and other setup operations.
The super.prepare method should always be called immediately The super.prepare method should always be called immediately
when subclassing. when subclassing.
*/ */
open func prepare() { open func prepare() {
clipsToBounds = false clipsToBounds = false
borderStyle = .none borderStyle = .none
backgroundColor = nil backgroundColor = nil
contentScaleFactor = Screen.scale contentScaleFactor = Screen.scale
font = RobotoFont.regular(with: 16) font = RobotoFont.regular(with: 16)
textColor = Color.darkText.primary textColor = Color.darkText.primary
prepareDivider() prepareDivider()
preparePlaceholderLabel() preparePlaceholderLabel()
prepareDetailLabel() prepareDetailLabel()
prepareTargetHandlers() prepareTargetHandlers()
prepareTextAlignment() prepareTextAlignment()
} }
/// Ensures that the components are sized correctly. /// Ensures that the components are sized correctly.
open func reload() { open func reload() {
layoutPlaceholderLabel() layoutPlaceholderLabel()
layoutDetailLabel() layoutDetailLabel()
layoutButton(button: clearIconButton) layoutButton(button: clearIconButton)
...@@ -688,8 +688,8 @@ extension TextField { ...@@ -688,8 +688,8 @@ extension TextField {
} }
updatePlaceholderLabelColor() updatePlaceholderLabelColor()
if self?.isPlaceholderUppercasedWhenEditing ?? false{ if self.isPlaceholderUppercasedWhenEditing {
s.placeholderLabel.text = s.placeholderLabel.text?.capitalized placeholderLabel.text = placeholderLabel.text?.capitalized
} }
guard isPlaceholderAnimated else { guard isPlaceholderAnimated else {
return return
......
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