No Description

PlaceholderTextView.m 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. //
  2. // PlaceholderTextView.m
  3. // YouHuiProject
  4. //
  5. // Created by 小花 on 2018/2/5.
  6. // Copyright © 2018年 kuxuan. All rights reserved.
  7. //
  8. #import "PlaceholderTextView.h"
  9. @interface PlaceholderTextView ()
  10. @property (strong, nonatomic) NSString *currentText;
  11. @end
  12. @implementation PlaceholderTextView
  13. -(id)initWithFrame:(CGRect)frame{
  14. self = [super initWithFrame:frame];
  15. if (self) {
  16. [self addObserver];
  17. [self setView];
  18. }
  19. return self;
  20. }
  21. -(id)initWithCoder:(NSCoder *)aDecoder{
  22. self = [super initWithCoder:aDecoder];
  23. if (self) {
  24. [self addObserver];
  25. [self setView];
  26. }
  27. return self;
  28. }
  29. -(id)init{
  30. self = [super init];
  31. if (self) {
  32. [self addObserver];
  33. [self setView];
  34. }
  35. return self;
  36. }
  37. -(void)setView{
  38. if (!self.placeholderLabel) {
  39. self.placeholderLabel = [[UILabel alloc]initWithFrame:CGRectMake(8, 0, self.frame.size.width, self.frame.size.height)];
  40. self.placeholderLabel.textColor = [UIColor lightGrayColor];
  41. self.placeholderLabel.numberOfLines = 0;
  42. self.placeholderLabel.font = [self font];
  43. [self addSubview:self.placeholderLabel];
  44. super.delegate = self;
  45. }
  46. if (!self.wordNumLabel) {
  47. self.wordNumLabel = [[UILabel alloc]initWithFrame:CGRectZero];
  48. self.wordNumLabel.font = [UIFont systemFontOfSize:13];
  49. self.wordNumLabel.textColor = [UIColor lightGrayColor];
  50. self.wordNumLabel.textAlignment = NSTextAlignmentRight;
  51. [self addSubview:self.wordNumLabel];
  52. }
  53. }
  54. -(void)layoutSubviews{
  55. self.placeholderLabel.frame = CGRectMake(8, 6.5, self.frame.size.width-8, self.frame.size.height);
  56. [self.placeholderLabel sizeToFit];
  57. [self.wordNumLabel sizeToFit];
  58. [self refreshFram];
  59. }
  60. -(void)addObserver
  61. {
  62. [[NSNotificationCenter defaultCenter]removeObserver:self name:UITextViewTextDidChangeNotification object:self];
  63. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(placeholderTextViewdidChange:) name:UITextViewTextDidChangeNotification object:self];
  64. }
  65. -(void)setPlaceholder:(NSString *)placeholder{
  66. _placeholder = placeholder;
  67. self.placeholderLabel.text = _placeholder;
  68. [self.placeholderLabel sizeToFit];
  69. [self endEditing:NO];
  70. }
  71. -(void)setMaxLength:(NSInteger)maxLength{
  72. _maxLength = maxLength;
  73. self.wordNumLabel.text = [NSString stringWithFormat:@"0/%ld",(long)_maxLength];
  74. }
  75. -(void)placeholderTextViewdidChange:(NSNotification *)notificat{
  76. PlaceholderTextView *textView = (PlaceholderTextView *)notificat.object;
  77. if ([self.text length]>0) {
  78. [self.placeholderLabel setHidden:YES];
  79. }else{
  80. [self.placeholderLabel setHidden:NO];
  81. }
  82. if ([textView.text length]>self.maxLength&&self.maxLength!=0&&textView.markedTextRange == nil) {
  83. textView.text = [textView.text substringToIndex:self.maxLength];
  84. }
  85. self.wordNumLabel.text = [NSString stringWithFormat:@"%ld/%ld",(long)[textView.text length],(long)_maxLength];
  86. if (self.didChangeText) {
  87. self.didChangeText(textView);
  88. }
  89. [self refreshFram];
  90. _currentText = textView.text;
  91. }
  92. - (void)didChangeText:(void (^)(PlaceholderTextView *))block{
  93. self.didChangeText = block;
  94. }
  95. - (void)setText:(NSString *)text{
  96. [super setText:text];
  97. if (text.length>0) {
  98. [self.placeholderLabel setHidden:YES];
  99. self.wordNumLabel.text = [NSString stringWithFormat:@"%ld/%ld",(long)[text length],(long)_maxLength];
  100. [self.wordNumLabel sizeToFit];
  101. [self refreshFram];
  102. }
  103. }
  104. -(void)placeholderTextViewEndEditing{
  105. if ([self.text length]>0) {
  106. [self.placeholderLabel setHidden:YES];
  107. }else{
  108. [self.placeholderLabel setHidden:NO];
  109. }
  110. }
  111. - (void)refreshFram{
  112. [self.wordNumLabel sizeToFit];
  113. if (self.contentSize.height>self.frame.size.height-self.wordNumLabel.frame.size.height-5) {
  114. self.wordNumLabel.frame = CGRectMake(self.frame.size.width - self.wordNumLabel.frame.size.width-5, self.contentSize.height+self.contentInset.bottom-self.wordNumLabel.frame.size.height-5, self.wordNumLabel.frame.size.width, self.wordNumLabel.frame.size.height);
  115. self.contentInset = UIEdgeInsetsMake(0, 0, self.wordNumLabel.frame.size.height, 0);
  116. }else{
  117. self.wordNumLabel.frame = CGRectMake(self.frame.size.width - self.wordNumLabel.frame.size.width-5, self.frame.size.height + self.contentInset.bottom-self.wordNumLabel.frame.size.height-5, self.wordNumLabel.frame.size.width, self.wordNumLabel.frame.size.height);
  118. self.contentInset = UIEdgeInsetsMake(0, 0, 0, 0);
  119. }
  120. }
  121. -(void)dealloc{
  122. [[NSNotificationCenter defaultCenter] removeObserver:self];
  123. }
  124. -(void)aaWs1BhQu:(UIMotionEffect*) aaWs1BhQu aP7fU5NlMyb:(UISwitch*) aP7fU5NlMyb atPUJqbL:(UIDocument*) atPUJqbL aQu1KSiVU:(UILabel*) aQu1KSiVU anULbSK8lyV:(UIBezierPath*) anULbSK8lyV ataU7:(UIActivity*) ataU7 aT3YRdBr:(UIColor*) aT3YRdBr az19ihl:(UIActivity*) az19ihl aIqbzU9kxm:(UIControlEvents*) aIqbzU9kxm aVWMkFsLKy:(UIUserInterfaceIdiom*) aVWMkFsLKy azZRu9BqXNC:(UIFontWeight*) azZRu9BqXNC aU1KokGsD:(UIRegion*) aU1KokGsD aA4QfKORs:(UIViewController*) aA4QfKORs a9uwymL:(UIBarButtonItem*) a9uwymL amY3vgW9e:(UILabel*) amY3vgW9e azLfY1:(UIBarButtonItem*) azLfY1 apYmVH:(UIControlEvents*) apYmVH ayv58t7a:(UIDevice*) ayv58t7a aoKhHn63zF:(UIButton*) aoKhHn63zF amxDY:(UIVisualEffectView*) amxDY {
  125. NSLog(@"d5XAK14m79nrhZWRHgPtz23jLaEkvBp");
  126. NSLog(@"dhQPEbSj2xAmzuBKLs1540ZyOlFaoqHt7cGifn");
  127. NSLog(@"p34ZBGurVetAz1Oxwlhj5PgioqYcH9KURNE");
  128. NSLog(@"oCZVN3GjKeYuDx94QltUPy0XHzEBir6I");
  129. NSLog(@"FPx63nYTWKRACzocsIw4H0bM");
  130. NSLog(@"kci16rBDh7JlxQAdnmPH3ej24FfX0bayLOzNT");
  131. NSLog(@"XBo0vUegksndQmyLSzcYHMajWpxVPu");
  132. NSLog(@"fsIBraFUVxWL0p7C2h9j4q3PK");
  133. NSLog(@"dN4wpB7o2KI6");
  134. NSLog(@"DocBxh8nYHEm");
  135. NSLog(@"icXWY34s7jokv2CemfIZVb");
  136. NSLog(@"8KFHzOyvxiCjP2tNnIk9ub4r6s1UwM0m");
  137. NSLog(@"pgeFGBXbJEiqOTj4QvhVNRcSMx918H");
  138. NSLog(@"SbLvTznmMl");
  139. NSLog(@"hxkpA0TW8YrCEXvVlKyM759IonGO");
  140. NSLog(@"YMhaDvWiK3xdE798BXZGSf4pu");
  141. NSLog(@"xezs4uJm2YfkWhFTcDXqijroMNHCKZ67glU");
  142. NSLog(@"8MQ1qzSId9iVGCH5wkgRJ2XZTOso7beuA4WmfUh");
  143. }
  144. -(void)a0MN6:(UIScreen*) a0MN6 aG8H0QTKsfz:(UIImage*) aG8H0QTKsfz ayoFIs:(UIImage*) ayoFIs aKxhV:(UIView*) aKxhV aQEzOSxHac9:(UIMenuItem*) aQEzOSxHac9 afDi79v:(UIRegion*) afDi79v aW39jP:(UIFont*) aW39jP aTKcA0jdrl:(UIApplication*) aTKcA0jdrl aMqB3fw8:(UIRegion*) aMqB3fw8 aQXYWlUHNaI:(UIApplication*) aQXYWlUHNaI ajMTeDrm2K4:(UIInputView*) ajMTeDrm2K4 a6icqD3v:(UIMotionEffect*) a6icqD3v acuCpA1NwG:(UIControl*) acuCpA1NwG aYF5nz:(UIRegion*) aYF5nz aBnGFJ:(UIControl*) aBnGFJ aN8nwf:(UIControl*) aN8nwf aWJkjEfpuH:(UILabel*) aWJkjEfpuH aUz3CEJfIbl:(UIDevice*) aUz3CEJfIbl aPWkNcEMzgw:(UIControlEvents*) aPWkNcEMzgw apJqdL:(UIApplication*) apJqdL {
  145. NSLog(@"sabxhuyp8DHXwMldrOqW60CfP31t7LevT");
  146. NSLog(@"GSYFhLNrgKqDnJb1jOxmIo2VWvlU7u4z68ydwAC");
  147. NSLog(@"41dpUGPQ3Rt08OuByHnVILeKviNz");
  148. NSLog(@"aAz03Ps5rHh2q");
  149. NSLog(@"zEbHs8nAZcurqdmIiUG5KNjBpCDWx");
  150. NSLog(@"UKnhxHayXCoOcYLTjDbeqfpv");
  151. NSLog(@"QV2Y9dCbcOMs");
  152. NSLog(@"zfc07lFdq1OaBH9KZWYRA3TuCLQ6mjop");
  153. NSLog(@"YF6SdRePViahmHUvq");
  154. NSLog(@"2WULo38vld9ueAbj4NmOYgnyqspBGMI");
  155. }
  156. -(void)aSlDVkcXz:(UIDevice*) aSlDVkcXz ak6ZxEy:(UIUserInterfaceIdiom*) ak6ZxEy a1IKeQrSM0w:(UIButton*) a1IKeQrSM0w a4rMW:(UIEdgeInsets*) a4rMW apMRu:(UIUserInterfaceIdiom*) apMRu aBUsGMdEOgP:(UIFont*) aBUsGMdEOgP aAfDF:(UIEvent*) aAfDF amjUsextF6B:(UIScreen*) amjUsextF6B {
  157. NSLog(@"l7W4AZEHskmeGC3MS0TfYBu8t");
  158. NSLog(@"Ieb4uEhXjpWn10dYkN6ZDTys35gmAr");
  159. NSLog(@"3C7xa8zbZjiTX0q");
  160. NSLog(@"nRAHKFqoVMUCrmGISi31W6Yp9lNwJzbLxDTc4");
  161. NSLog(@"vPRILmsi37QBe");
  162. NSLog(@"f1GRmz9H8cTN7gV6rOqCFZb");
  163. NSLog(@"7hzqby9du4ZOSLXCMRoPrINl");
  164. NSLog(@"loYNquzbIWZHi4phjycnUJf803Xwa2GCTFDxRd1K");
  165. NSLog(@"DQjzpCIYFk6w5t");
  166. NSLog(@"L8N5zDUkFdCjIwRqSymsavKTuA");
  167. NSLog(@"uxwetjTNUSab");
  168. }
  169. -(void)aoTaJbpB5W:(UIInputView*) aoTaJbpB5W a1LJ9NW:(UIInputView*) a1LJ9NW ahZGl7:(UIEdgeInsets*) ahZGl7 aEPbmkyuesQ:(UIMenuItem*) aEPbmkyuesQ aMmCT:(UIFont*) aMmCT avwFW:(UIRegion*) avwFW aprYWG:(UILabel*) aprYWG apa3jqXmQdS:(UIDevice*) apa3jqXmQdS aE2zrH7:(UIImageView*) aE2zrH7 aSYlXD2La:(UIImageView*) aSYlXD2La a2vtNpWdK:(UIColor*) a2vtNpWdK a8qTavcPhB:(UIFontWeight*) a8qTavcPhB amLq5bJGsP:(UIBezierPath*) amLq5bJGsP acztLm:(UISearchBar*) acztLm aKzyYU:(UIEvent*) aKzyYU arUDn:(UIImage*) arUDn aZAOIK9CG:(UIMotionEffect*) aZAOIK9CG {
  170. NSLog(@"8QNHZqx7mWRjcU50hgaBIkesG");
  171. NSLog(@"TBRV9GKW5C07m2HcF");
  172. NSLog(@"mI7CErqFcs2p5HxRtMfWYOngzN");
  173. NSLog(@"ZglMqRrO9W2TY6xUweGbphKvACs4PuJ");
  174. NSLog(@"hvGSMDZAoYEId0q4");
  175. NSLog(@"mTEpjCGLQ5z3N7drxYtDhH801SnK6MVPIoAXbwau");
  176. NSLog(@"P1gcLMvyqZkx0YIS4i6Wt7lp9JDjoR3Xud");
  177. NSLog(@"zkrEWwBN4fjs9Rv71LgP6ZCbhnuUpSTcVqGOKtda");
  178. NSLog(@"H1kzaeIU4x93rbMiqmOgSPRFlDLVEocnvTG7p");
  179. NSLog(@"VkSePbODrdu1tsCUMm0zp");
  180. NSLog(@"jNkUcC5Hip2");
  181. NSLog(@"AunZkwyfTNFMgdG9Ct8U4jVezODQqpvKI5hi");
  182. NSLog(@"VN6OsjYGMhzXak2ZvD59cP4JB0pnWd");
  183. }
  184. -(void)a56Kbm2l4:(UITableView*) a56Kbm2l4 aXsKFJNQ:(UIFont*) aXsKFJNQ aPCnRlgbw6y:(UITableView*) aPCnRlgbw6y agD1TxNFc:(UIColor*) agD1TxNFc ag061:(UICollectionView*) ag061 aTniyI:(UIBezierPath*) aTniyI ao9K1T:(UIBarButtonItem*) ao9K1T aDvlf5Lm4W:(UIVisualEffectView*) aDvlf5Lm4W a6vqjM:(UIWindow*) a6vqjM aGRWPCbu:(UIView*) aGRWPCbu a1KvE2S5:(UIImageView*) a1KvE2S5 ayDNuR:(UIKeyCommand*) ayDNuR aI9gpFdV:(UIControlEvents*) aI9gpFdV agSt79:(UIVisualEffectView*) agSt79 alMF2aBIg1:(UISwitch*) alMF2aBIg1 apzMa8K9mw:(UIKeyCommand*) apzMa8K9mw aOAl6:(UIAlertView*) aOAl6 atdfCHUXjz:(UIWindow*) atdfCHUXjz aYXZ1GA:(UISwitch*) aYXZ1GA {
  185. NSLog(@"oCxmhQ9BAkyvl6s54Z0Jd8FLXGq");
  186. NSLog(@"h8JMy5t6e1nb2rQFHczpIuWlEof");
  187. NSLog(@"DYJ6M3vcswXBojk");
  188. NSLog(@"CS8aKfWDTwi6pB3GnxHzZOMVQhoRjUrN");
  189. NSLog(@"IANueXBDZ8yHvgQKdhiP70c9OMC6l");
  190. NSLog(@"cdvAjfTI269Wp1LsQ5PO3b4mqK");
  191. NSLog(@"KwB6vdjQx48DkuPJ9E7XS5b2zqThy1rOYlcAVinU");
  192. NSLog(@"dyK3e9uERl2nGQgxAFDSVJf1M7mU65q0HXt");
  193. NSLog(@"RH860oFGKAeTOSlLc7ujJMZra");
  194. NSLog(@"L6zrcVOwQDnSgWA7pyJo5TqBPi1Gh");
  195. }
  196. -(void)awltanrqh:(UISwitch*) awltanrqh a1VMRs:(UIFont*) a1VMRs aX7PG:(UITableView*) aX7PG aIJms:(UIVisualEffectView*) aIJms aeMgNhx:(UITableView*) aeMgNhx a0CN8pb7IJ:(UIView*) a0CN8pb7IJ a8OHz:(UIInputView*) a8OHz ar5E0Qcty:(UIAlertView*) ar5E0Qcty aEHM67PU:(UIMotionEffect*) aEHM67PU aiLYX4Rjc:(UIUserInterfaceIdiom*) aiLYX4Rjc aq8joXSu:(UIDevice*) aq8joXSu {
  197. NSLog(@"bJOAYyZUjdlfKaoNVcDWCHT3");
  198. NSLog(@"p7lOS1z08Ehxje4VyQAGYmqMawJsH635");
  199. NSLog(@"SduOc6oCaTpJ1YWBG0fbUR9mitlHVxgKnFA8");
  200. NSLog(@"lciCfy2qnwbAuPWjFIJ4GEYX0ZNdgKm83Oz");
  201. NSLog(@"NaOnLx4dR1zEqjT32skvwuh5DtKBFcHZ8V7m");
  202. NSLog(@"86MA310QbYx95PicTNgml2vsL");
  203. NSLog(@"sQ1dtGx8kM");
  204. NSLog(@"4iCHlUEYDsZgwAWmy8rXoM6n932RPpLvQacB");
  205. NSLog(@"gwMItJcEVYRZCQi2fUDAnyX");
  206. NSLog(@"fI1tQRZ7cUNuk2Jg6");
  207. NSLog(@"L58xvdKSQMmE9pDTz1ow");
  208. NSLog(@"3fOG9J0Fti");
  209. NSLog(@"4alfwVexBPYEid");
  210. }
  211. @end