From e450757613e8388874d62338cddc593662edf616 Mon Sep 17 00:00:00 2001 From: onl1ner Date: Sun, 9 Aug 2020 13:40:34 +0600 Subject: [PATCH] Fixed delegation issues --- STTextView/STTextView.podspec | 2 +- .../UserInterfaceState.xcuserstate | Bin 19133 -> 19173 bytes STTextView/STTextView/STTextView.swift | 37 ++++++++++-------- 3 files changed, 21 insertions(+), 18 deletions(-) diff --git a/STTextView/STTextView.podspec b/STTextView/STTextView.podspec index 60fd649..bf59a0e 100644 --- a/STTextView/STTextView.podspec +++ b/STTextView/STTextView.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |spec| spec.name = "STTextView" - spec.version = "1.1.0" + spec.version = "1.1.1" spec.summary = "STTextView is a light-weight CocoaPod that adds a placeholder to the UITextView." diff --git a/STTextView/STTextView.xcodeproj/project.xcworkspace/xcuserdata/onl1ner.xcuserdatad/UserInterfaceState.xcuserstate b/STTextView/STTextView.xcodeproj/project.xcworkspace/xcuserdata/onl1ner.xcuserdatad/UserInterfaceState.xcuserstate index bd619289a353e1b88acf6b440b19bad976dd2d91..73cee689340db03e649cba73f9e0558fb0b0af2f 100644 GIT binary patch delta 6120 zcmZu!34Baf7r*D;H<>N7znM3aVD`xjK|~0u%mmT2)`SpS1cPXZCb6c>ol^V$(5f|w zEv1xDs#SY~6tydASJb}LzI<41#PJ44*&_EdCvz!{_k@d=X#5m+=*R z72n2p@Ll{Dk&|$uAWEVlYN8=pq9ZIZ5;KV+ZW2T4ka+SQX-pDHOY#9pBCSaZ=|DP? z?xY7vCp}3?8ZhF>;)oAScO1a*13fe~`!I33*DMk>}(!0}N)u zm~ckT=olkYg{j)nF=$8@|08Y)zwnPSh5aSNNJkLQqzhGi^+p(gfO^CLTrm(0(LGWvCN6z^i2}7e||PN$JqR zKRhor(?9G8nu?~OU(sPcOJ*j8=mv`M;J{ccUI++mr0^VGOf z_UVvp+Km3U*xmhQ`qax2y_eGMt9I%bPwG} zD}?6(dWaqg?_Yd#`EqHJ+N8GA57kEgp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(-c-LTz?W~19gkBA-{Jw7@Z%|*|QUJ$(~x+uCNdU5o<=qL6FyDVsr zvMcR6yWVcJvv#Z9ZEt38ZSQO!ZXaczV_#+8XFp*-X+LGJuwS-cwO841*l*c?wLf)4 zIg}2yL+fB128YREcGPs#cEmXvINo+Nax``{bu@Rhbod>~j#S402j^JgIOw?JR5=?s zyE;cW$2!M5gHFyl$;mr|vz>FC^PFEf7dpRju5qq&Zg6gOZg=is?g&2-In&2i0hmAY2D4!X{{?zhyzA-b$@FA-hI>YN#(KtksOMA9B+pdO zbk9uB4$n=m-do%2^u~IddsDovz3sdmz1_S$yuH1By&2vi-uJx2z2m(Tyq|g}d8c}3 zdFOcNdl!0xUwfB(S9mvj_j`|ck9$vgE4=5tKY1^EuX?MzcfAk2FMLyd(|ikjWxkcZ zHNN$}O}?$Z9lk@pqrT(5lfDXHrSGioN8by--QUqa%1`~D`DgfN`4{>Z`^)^h{oncz z`;Ym{{U`lD`7isg_^bRk{I~oM{Ez%k{C_5qBvF&3$Rt$~lVnI@lWHV+lIkSIB)yg7 ZOG-^@U)^J2;a`i;Pvoh7zPcxM{5Q8Hd;kCd diff --git a/STTextView/STTextView/STTextView.swift b/STTextView/STTextView/STTextView.swift index 0960d0b..1fd0f31 100644 --- a/STTextView/STTextView/STTextView.swift +++ b/STTextView/STTextView/STTextView.swift @@ -22,7 +22,7 @@ import UIKit -@IBDesignable open class STTextView : UITextView, UITextViewDelegate { +@IBDesignable open class STTextView : UITextView { /// Placeholder string that will be shown in your TextView. @IBInspectable public var placeholder : String = "Enter your placeholder" { @@ -85,27 +85,24 @@ import UIKit return textView }() - public func textViewShouldBeginEditing(_ textView: UITextView) -> Bool { - if textView.text.isEmpty { + @objc private func textDidBeginEditing() -> () { + if self.text.isEmpty { if shouldHidePlaceholderOnEditing { placeholderTextView.isHidden = true } } - return true } - public func textViewShouldEndEditing(_ textView: UITextView) -> Bool { - placeholderTextView.isHidden = !textView.text.isEmpty - return true + @objc private func textDidChange() -> () { + placeholderTextView.isHidden = !self.text.isEmpty } - - public func textView(_ textView: UITextView, shouldChangeTextIn range: NSRange, replacementText text: String) -> Bool { - let currentContent : NSString = NSString(string: textView.text) - let newContent = currentContent.replacingCharacters(in: range, with: text) - - self.placeholderTextView.isHidden = !newContent.isEmpty - - return true + + @objc private func textDidEndEditing() -> () { + if self.text.isEmpty { + if shouldHidePlaceholderOnEditing { + placeholderTextView.isHidden = false + } + } } // Method is used to update the placeholderTextView whenever @@ -118,10 +115,16 @@ import UIKit placeholderTextView.textAlignment = self.textAlignment } + private func signForNotifications() -> () { + NotificationCenter.default.addObserver(self, selector: #selector(textDidChange), name: UITextView.textDidChangeNotification, object: nil) + NotificationCenter.default.addObserver(self, selector: #selector(textDidBeginEditing), name: UITextView.textDidBeginEditingNotification, object: nil) + NotificationCenter.default.addObserver(self, selector: #selector(textDidEndEditing), name: UITextView.textDidEndEditingNotification, object: nil) + } + private func initialConfiguration() -> () { - self.delegate = self - self.insertSubview(placeholderTextView, at: 0) + + signForNotifications() } public override func prepareForInterfaceBuilder() {