From 93609345b3ad1eb25c0768d96875c6e4fa64d538 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Lo=CC=81pez=20Ferna=CC=81ndez?= Date: Thu, 22 Nov 2018 12:26:06 +0100 Subject: [PATCH 1/3] Added properties to customize vertical spacing between line, title and textfield. --- Sources/SkyFloatingLabelTextField.swift | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/Sources/SkyFloatingLabelTextField.swift b/Sources/SkyFloatingLabelTextField.swift index 3bb382c..6077599 100644 --- a/Sources/SkyFloatingLabelTextField.swift +++ b/Sources/SkyFloatingLabelTextField.swift @@ -188,6 +188,20 @@ open class SkyFloatingLabelTextField: UITextField { // swiftlint:disable:this ty setNeedsDisplay() } } + + // MARK: Components spacing + + @IBInspectable dynamic open var lineVerticalSpacing: CGFloat = 0 { + didSet { + setNeedsDisplay() + } + } + + @IBInspectable dynamic open var titleVerticalSpacing: CGFloat = 0 { + didSet { + setNeedsDisplay() + } + } // MARK: View components @@ -568,7 +582,7 @@ open class SkyFloatingLabelTextField: UITextField { // swiftlint:disable:this ty x: superRect.origin.x, y: titleHeight, width: superRect.size.width, - height: superRect.size.height - titleHeight - selectedLineHeight + height: superRect.size.height - titleHeight - selectedLineHeight - lineVerticalSpacing ) return rect } @@ -586,7 +600,7 @@ open class SkyFloatingLabelTextField: UITextField { // swiftlint:disable:this ty x: superRect.origin.x, y: titleHeight, width: superRect.size.width, - height: superRect.size.height - titleHeight - selectedLineHeight + height: superRect.size.height - titleHeight - selectedLineHeight - lineVerticalSpacing ) return rect } @@ -601,7 +615,7 @@ open class SkyFloatingLabelTextField: UITextField { // swiftlint:disable:this ty x: 0, y: titleHeight(), width: bounds.size.width, - height: bounds.size.height - titleHeight() - selectedLineHeight + height: bounds.size.height - titleHeight() - selectedLineHeight - lineVerticalSpacing ) return rect } @@ -640,7 +654,7 @@ open class SkyFloatingLabelTextField: UITextField { // swiftlint:disable:this ty open func titleHeight() -> CGFloat { if let titleLabel = titleLabel, let font = titleLabel.font { - return font.lineHeight + return font.lineHeight + titleVerticalSpacing } return 15.0 } @@ -687,7 +701,7 @@ open class SkyFloatingLabelTextField: UITextField { // swiftlint:disable:this ty - returns: the content size to be used for auto layout */ override open var intrinsicContentSize: CGSize { - return CGSize(width: bounds.size.width, height: titleHeight() + textHeight()) + return CGSize(width: bounds.size.width, height: titleHeight() + textHeight() + lineVerticalSpacing) } // MARK: - Helpers From 76a855f3ea47e7ee804eee7d57fe975b8384cbfa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Lo=CC=81pez=20Ferna=CC=81ndez?= Date: Thu, 22 Nov 2018 12:37:24 +0100 Subject: [PATCH 2/3] Readme updated --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index 1a12569..6e7c00b 100644 --- a/README.md +++ b/README.md @@ -119,6 +119,12 @@ textField1.iconImage = UIImage(imageLiteralResourceName: "PlaneIcon") self.view.addSubview(textField1) ``` +### Title and line spacing +```swift +userTextField.titleVerticalSpacing = 10 +userTextField.lineVerticalSpacing = 5 +``` + ### Error state and delegates The textfield supports displaying an error state - this can be useful for example when validating fields on the fly. When the `errorMessage` property is set on the control, then the control is highlighted with the color set in the `errorColor` property. From bb19c5cdf4c6638a8471e7690352f7d2e1e5b504 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Lo=CC=81pez=20Ferna=CC=81ndez?= Date: Thu, 22 Nov 2018 14:27:27 +0100 Subject: [PATCH 3/3] Show title always --- Sources/SkyFloatingLabelTextField.swift | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Sources/SkyFloatingLabelTextField.swift b/Sources/SkyFloatingLabelTextField.swift index 6077599..773e6ca 100644 --- a/Sources/SkyFloatingLabelTextField.swift +++ b/Sources/SkyFloatingLabelTextField.swift @@ -246,6 +246,9 @@ open class SkyFloatingLabelTextField: UITextField { // swiftlint:disable:this ty updateControl(true) } } + + @IBInspectable + open var alwaysShowTitle: Bool = false /// The backing property for the highlighted property fileprivate var _highlighted: Bool = false @@ -503,7 +506,7 @@ open class SkyFloatingLabelTextField: UITextField { // swiftlint:disable:this ty if hasErrorMessage { titleText = titleFormatter(errorMessage!) } else { - if editingOrSelected { + if editingOrSelected || alwaysShowTitle { titleText = selectedTitleOrTitlePlaceholder() if titleText == nil { titleText = titleOrPlaceholder() @@ -541,7 +544,7 @@ open class SkyFloatingLabelTextField: UITextField { // swiftlint:disable:this ty - returns: True if the title is displayed on the control, false otherwise. */ open func isTitleVisible() -> Bool { - return hasText || hasErrorMessage || _titleVisible + return hasText || hasErrorMessage || _titleVisible || alwaysShowTitle } fileprivate func updateTitleVisibility(_ animated: Bool = false, completion: ((_ completed: Bool) -> Void)? = nil) {