From a8303908c7eda89d04f0008a3c23feb7c023dfc8 Mon Sep 17 00:00:00 2001 From: DamienBallenghien Date: Thu, 5 Jul 2018 16:33:57 +0200 Subject: [PATCH 1/5] Add placeholderFont handling --- AnimatedTextInput/Classes/AnimatedTextInput.swift | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/AnimatedTextInput/Classes/AnimatedTextInput.swift b/AnimatedTextInput/Classes/AnimatedTextInput.swift index a6b74ca..b4e2659 100755 --- a/AnimatedTextInput/Classes/AnimatedTextInput.swift +++ b/AnimatedTextInput/Classes/AnimatedTextInput.swift @@ -244,7 +244,7 @@ open class AnimatedTextInput: UIControl { fileprivate func layoutPlaceholderLayer() { // Some letters like 'g' or 'รก' were not rendered properly, the frame need to be about 20% higher than the font size let frameHeightCorrectionFactor: CGFloat = 1.2 - placeholderLayer.frame = CGRect(origin: placeholderPosition, size: CGSize(width: bounds.width, height: style.textInputFont.pointSize * frameHeightCorrectionFactor)) + placeholderLayer.frame = CGRect(origin: placeholderPosition, size: CGSize(width: bounds.width, height: style.placeHolderFont.pointSize * frameHeightCorrectionFactor)) } // mark: Configuration @@ -285,8 +285,8 @@ open class AnimatedTextInput: UIControl { placeholderLayer.masksToBounds = false placeholderLayer.string = placeHolderText placeholderLayer.foregroundColor = style.placeholderInactiveColor.cgColor - placeholderLayer.fontSize = style.textInputFont.pointSize - placeholderLayer.font = style.textInputFont + placeholderLayer.fontSize = style.placeHolderFont.pointSize + placeholderLayer.font = style.placeHolderFont placeholderLayer.contentsScale = UIScreen.main.scale placeholderLayer.backgroundColor = UIColor.clear.cgColor layoutPlaceholderLayer() @@ -337,7 +337,7 @@ open class AnimatedTextInput: UIControl { fileprivate func configurePlaceholderAsDefault() { isPlaceholderAsHint = false - configurePlaceholderWith(fontSize: style.textInputFont.pointSize, + configurePlaceholderWith(fontSize: style.placeHolderFont.pointSize, foregroundColor: style.placeholderInactiveColor.cgColor, text: placeHolderText) lineView.animateToInitialState() @@ -378,9 +378,9 @@ open class AnimatedTextInput: UIControl { fileprivate func styleDidChange() { lineView.defaultColor = style.lineInactiveColor placeholderLayer.foregroundColor = style.placeholderInactiveColor.cgColor - let fontSize = style.textInputFont.pointSize + let fontSize = style.placeHolderFont.pointSize placeholderLayer.fontSize = fontSize - placeholderLayer.font = style.textInputFont + placeholderLayer.font = style.placeHolderFont textInput.view.tintColor = style.activeColor textInput.textColor = style.textInputFontColor textInput.font = style.textInputFont From ddee3f635db622af8637475ca364e9f8d692961e Mon Sep 17 00:00:00 2001 From: DamienBallenghien Date: Thu, 5 Jul 2018 16:35:20 +0200 Subject: [PATCH 2/5] Add placeholderFont property --- AnimatedTextInput/Classes/AnimatedTextInputStyle.swift | 2 ++ 1 file changed, 2 insertions(+) diff --git a/AnimatedTextInput/Classes/AnimatedTextInputStyle.swift b/AnimatedTextInput/Classes/AnimatedTextInputStyle.swift index 5c81b76..1aad94f 100644 --- a/AnimatedTextInput/Classes/AnimatedTextInputStyle.swift +++ b/AnimatedTextInput/Classes/AnimatedTextInputStyle.swift @@ -9,6 +9,7 @@ public protocol AnimatedTextInputStyle { var lineHeight: CGFloat { get } var errorColor: UIColor { get } var textInputFont: UIFont { get } + var placeHolderFont: UIFont { get } var textInputFontColor: UIColor { get } var placeholderMinFontSize: CGFloat { get } var counterLabelFont: UIFont? { get } @@ -31,6 +32,7 @@ public struct AnimatedTextInputStyleBlue: AnimatedTextInputStyle { public let lineHeight: CGFloat = 1.0 / UIScreen.main.scale public let errorColor = UIColor.red public let textInputFont = UIFont.systemFont(ofSize: 14) + public let placeHolderFont = UIFont.systemFont(ofSize: 14) public let textInputFontColor = UIColor.black public let placeholderMinFontSize: CGFloat = 9 public let counterLabelFont: UIFont? = UIFont.systemFont(ofSize: 9) From 0491889fd6ece944b47c37e2af1a071a0dbdaec1 Mon Sep 17 00:00:00 2001 From: ink-spot Date: Wed, 26 Sep 2018 12:34:55 +0200 Subject: [PATCH 3/5] Draw password toggleable icon with active color --- AnimatedTextInput/Classes/AnimatedTextInput.swift | 14 +++++++++++++- AnimatedTextInput/Classes/AnimatedTextView.swift | 5 +++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/AnimatedTextInput/Classes/AnimatedTextInput.swift b/AnimatedTextInput/Classes/AnimatedTextInput.swift index 0d8836c..f271a06 100755 --- a/AnimatedTextInput/Classes/AnimatedTextInput.swift +++ b/AnimatedTextInput/Classes/AnimatedTextInput.swift @@ -313,6 +313,7 @@ open class AnimatedTextInput: UIControl { textInput.font = style.textInputFont textInput.autocorrection = autocorrection textInput.view.translatesAutoresizingMaskIntoConstraints = false + configureRightView() addSubview(textInput.view) invalidateIntrinsicContentSize() } @@ -372,6 +373,15 @@ open class AnimatedTextInput: UIControl { transactionAnimation(with: duration, timingFuncion: function, animations: applyConfiguration) } + fileprivate func configureRightView() { + if let button = textInput.rightView as? UIButton { + if let selectedImage = button.image(for: .selected) { + button.tintColor = style.activeColor + button.setImage(selectedImage.withRenderingMode(.alwaysTemplate), for: .selected) + } + } + } + // mark: Behaviours @objc fileprivate func viewWasTapped(sender: UIGestureRecognizer) { @@ -391,6 +401,7 @@ open class AnimatedTextInput: UIControl { textInput.view.tintColor = style.activeColor textInput.textColor = style.textInputFontColor textInput.font = style.textInputFont + configureRightView() invalidateIntrinsicContentSize() layoutIfNeeded() } @@ -583,7 +594,8 @@ public protocol TextInput { var currentBeginningOfDocument: UITextPosition? { get } var currentKeyboardAppearance: UIKeyboardAppearance { get set } var contentInset: UIEdgeInsets { get set } - var autocorrection: UITextAutocorrectionType {get set} + var autocorrection: UITextAutocorrectionType { get set } + var rightView: UIView? { get set } func configureInputView(newInputView: UIView) diff --git a/AnimatedTextInput/Classes/AnimatedTextView.swift b/AnimatedTextInput/Classes/AnimatedTextView.swift index 6ba1eff..987bfef 100755 --- a/AnimatedTextInput/Classes/AnimatedTextView.swift +++ b/AnimatedTextInput/Classes/AnimatedTextView.swift @@ -70,6 +70,11 @@ extension AnimatedTextView: TextInput { set { self.autocorrectionType = newValue } } + public var rightView: UIView? { + get { return nil } + set { } + } + public func changeReturnKeyType(with newReturnKeyType: UIReturnKeyType) { returnKeyType = newReturnKeyType } From 0e63d0d33900d1f33fa01fda3f487e9dfc972f13 Mon Sep 17 00:00:00 2001 From: Alex Agapov Date: Fri, 15 Mar 2019 11:58:44 +0500 Subject: [PATCH 4/5] Update example project to compile with new placeholder font property --- Example/AnimatedTextInput/ViewController.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/Example/AnimatedTextInput/ViewController.swift b/Example/AnimatedTextInput/ViewController.swift index 59334df..26ef145 100644 --- a/Example/AnimatedTextInput/ViewController.swift +++ b/Example/AnimatedTextInput/ViewController.swift @@ -78,6 +78,7 @@ struct CustomTextInputStyle: AnimatedTextInputStyle { let lineHeight: CGFloat = 3 let errorColor = UIColor.red let textInputFont = UIFont.systemFont(ofSize: 14) + let placeHolderFont = UIFont.systemFont(ofSize: 14) let textInputFontColor = UIColor.black let placeholderMinFontSize: CGFloat = 9 let counterLabelFont: UIFont? = UIFont.systemFont(ofSize: 9) From d9592021568a7d0ea4c3d19e582a82346fa7ec33 Mon Sep 17 00:00:00 2001 From: Alex Agapov Date: Fri, 15 Mar 2019 11:58:47 +0500 Subject: [PATCH 5/5] Update readme --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index ffa5504..f116ee2 100644 --- a/README.md +++ b/README.md @@ -52,6 +52,7 @@ struct CustomTextInputStyle: AnimatedTextInputStyle { let inactiveColor = UIColor.grayColor().colorWithAlphaComponent(0.3) let errorColor = UIColor.redColor() let textInputFont = UIFont.systemFontOfSize(14) + let placeholderFont = UIFont.systemFont(ofSize: 14) let textInputFontColor = UIColor.blackColor() let placeholderMinFontSize: CGFloat = 9 let counterLabelFont: UIFont? = UIFont.systemFontOfSize(9)