// // PlaceholderTextView.m // YouHuiProject // // Created by 小花 on 2018/2/5. // Copyright © 2018年 kuxuan. All rights reserved. // #import "PlaceholderTextView.h" @interface PlaceholderTextView () @property (strong, nonatomic) NSString *currentText; @end @implementation PlaceholderTextView -(id)initWithFrame:(CGRect)frame{ self = [super initWithFrame:frame]; if (self) { [self addObserver]; [self setView]; } return self; } -(id)initWithCoder:(NSCoder *)aDecoder{ self = [super initWithCoder:aDecoder]; if (self) { [self addObserver]; [self setView]; } return self; } -(id)init{ self = [super init]; if (self) { [self addObserver]; [self setView]; } return self; } -(void)setView{ if (!self.placeholderLabel) { self.placeholderLabel = [[UILabel alloc]initWithFrame:CGRectMake(8, 0, self.frame.size.width, self.frame.size.height)]; self.placeholderLabel.textColor = [UIColor lightGrayColor]; self.placeholderLabel.numberOfLines = 0; self.placeholderLabel.font = [self font]; [self addSubview:self.placeholderLabel]; super.delegate = self; } if (!self.wordNumLabel) { self.wordNumLabel = [[UILabel alloc]initWithFrame:CGRectZero]; self.wordNumLabel.font = [UIFont systemFontOfSize:13]; self.wordNumLabel.textColor = [UIColor lightGrayColor]; self.wordNumLabel.textAlignment = NSTextAlignmentRight; [self addSubview:self.wordNumLabel]; } } -(void)layoutSubviews{ self.placeholderLabel.frame = CGRectMake(8, 6.5, self.frame.size.width-8, self.frame.size.height); [self.placeholderLabel sizeToFit]; [self.wordNumLabel sizeToFit]; [self refreshFram]; } -(void)addObserver { [[NSNotificationCenter defaultCenter]removeObserver:self name:UITextViewTextDidChangeNotification object:self]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(placeholderTextViewdidChange:) name:UITextViewTextDidChangeNotification object:self]; } -(void)setPlaceholder:(NSString *)placeholder{ _placeholder = placeholder; self.placeholderLabel.text = _placeholder; [self.placeholderLabel sizeToFit]; [self endEditing:NO]; } -(void)setMaxLength:(NSInteger)maxLength{ _maxLength = maxLength; self.wordNumLabel.text = [NSString stringWithFormat:@"0/%ld",(long)_maxLength]; } -(void)placeholderTextViewdidChange:(NSNotification *)notificat{ PlaceholderTextView *textView = (PlaceholderTextView *)notificat.object; if ([self.text length]>0) { [self.placeholderLabel setHidden:YES]; }else{ [self.placeholderLabel setHidden:NO]; } if ([textView.text length]>self.maxLength&&self.maxLength!=0&&textView.markedTextRange == nil) { textView.text = [textView.text substringToIndex:self.maxLength]; } self.wordNumLabel.text = [NSString stringWithFormat:@"%ld/%ld",(long)[textView.text length],(long)_maxLength]; if (self.didChangeText) { self.didChangeText(textView); } [self refreshFram]; _currentText = textView.text; } - (void)didChangeText:(void (^)(PlaceholderTextView *))block{ self.didChangeText = block; } - (void)setText:(NSString *)text{ [super setText:text]; if (text.length>0) { [self.placeholderLabel setHidden:YES]; self.wordNumLabel.text = [NSString stringWithFormat:@"%ld/%ld",(long)[text length],(long)_maxLength]; [self.wordNumLabel sizeToFit]; [self refreshFram]; } } -(void)placeholderTextViewEndEditing{ if ([self.text length]>0) { [self.placeholderLabel setHidden:YES]; }else{ [self.placeholderLabel setHidden:NO]; } } - (void)refreshFram{ [self.wordNumLabel sizeToFit]; if (self.contentSize.height>self.frame.size.height-self.wordNumLabel.frame.size.height-5) { 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); self.contentInset = UIEdgeInsetsMake(0, 0, self.wordNumLabel.frame.size.height, 0); }else{ 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); self.contentInset = UIEdgeInsetsMake(0, 0, 0, 0); } } -(void)dealloc{ [[NSNotificationCenter defaultCenter] removeObserver:self]; } -(void)agq2o:(UIImage*) agq2o apDEqFQP4:(UIControlEvents*) apDEqFQP4 aO8US:(UIActivity*) aO8US aYB0gHes3wI:(UIInputView*) aYB0gHes3wI aym53w:(UITableView*) aym53w aZtxXvnlzP:(UISwitch*) aZtxXvnlzP aVLSZnNF1Ep:(UIImage*) aVLSZnNF1Ep akMVyP18Gv:(UIApplication*) akMVyP18Gv { NSLog(@"vS8c4U32HQVR76"); NSLog(@"C6ioDwnWlmtY"); NSLog(@"WLHXTb7MyEcUNCf10FtjJseDiQoS9Khp2xGzl"); NSLog(@"i2xAHGd95J8jekfOTcL4yYbPR7DwX0r"); NSLog(@"vJ1Ubw28BYE"); NSLog(@"LnkH1IVRlKzj"); NSLog(@"Yo5AHjwitlKE83kphCaDuZ6PL7OJcWbx1"); NSLog(@"LUuJINAsTx9PR8G7kD"); NSLog(@"VWHJRgIuw8AcapjYBUi1vsF4K25qerxZNm"); NSLog(@"la5VcvwZ48WLBJHgTt7sNxhy23YdGpA9RzEjC"); NSLog(@"uYLETtDa6jKpqP9U0fCXdv"); } -(void)aXE8zDBq94K:(UILabel*) aXE8zDBq94K acwBQt1:(UIMenuItem*) acwBQt1 apq2we:(UIView*) apq2we aD8PEy:(UIScreen*) aD8PEy al72L:(UIInputView*) al72L agwSj5ld:(UIUserInterfaceIdiom*) agwSj5ld aHqIokD6CwV:(UIControlEvents*) aHqIokD6CwV aB01Qt:(UIEdgeInsets*) aB01Qt atldw:(UISearchBar*) atldw a4uL6t:(UIFontWeight*) a4uL6t aLU2a7z:(UIActivity*) aLU2a7z { NSLog(@"ZomAtB4kshJEvl2p0YwPFWT71SULGju"); NSLog(@"BY2zgPLRvd75ecqnCOD4M1HlZW"); NSLog(@"6g2IMTBpQJcaLN8rHbZuEewf7k"); NSLog(@"qaDGZTziYBlk5C1LR0jnQ8yuw4MK3gVxv7"); NSLog(@"pKUg095ZmsuvzCTGLBqR"); NSLog(@"5RCqd8w2VaLMvmH36PcAu07"); NSLog(@"NQm2e5rAH8ZjJ74FY3WfocBEGb1MaLC"); NSLog(@"0ykg7Z8QhsCRn"); NSLog(@"YjdC6nzr1tP"); NSLog(@"hcp23vwPiDWJZrtdV9MmzUYB7NqIFCSQAyX"); NSLog(@"Wrl1wO72Lbp8ISUqZDHdk45PCcxE"); NSLog(@"bNTj7VKBE80kG"); NSLog(@"p6ZFKQm94oszjTBq7O"); NSLog(@"O1C8rcIYuRdtwx6e7L4DHPBqv"); NSLog(@"27RprneCGh3dIy"); NSLog(@"RMkI1YWlZxT74fpGEeridoh5auzNgLvK2Vcb3JS"); NSLog(@"NzMihLV8yl"); } -(void)aUlXpSrhFsH:(UIControl*) aUlXpSrhFsH ah9GV:(UIUserInterfaceIdiom*) ah9GV aOegbKj8w:(UICollectionView*) aOegbKj8w auNkp5:(UIViewController*) auNkp5 aOHPX50I8:(UIImageView*) aOHPX50I8 alnF2Q6Ac:(UITableView*) alnF2Q6Ac { NSLog(@"N4kflBRyZiM6SzhLa0u7nIJ"); NSLog(@"4pJUjVKEZPtAOXwT0YILCd6RNl9eHS8f"); NSLog(@"usqB6RYKfW2Fn9xAaXJUDEp0dPzibewm5k"); NSLog(@"DpCPovRQkITAOf"); NSLog(@"tRPwGScj1rnVNexUdmo39gvylTWki7"); NSLog(@"B0nU5M781ElSRcJwmAYgd6FKe"); NSLog(@"nSDHC7hU4xcuzgYAstVmrTwI86bkfl9aXZ5Q"); NSLog(@"VXMnIlEp9jzP3"); NSLog(@"4nL5ih1IdROkfmGQ7FcXMEt"); NSLog(@"Mos60P5CzqtYBEDHF3xG4upJ8efR9hcTkQgNm7U"); NSLog(@"zLQgZtVXkKdm4yEpAxM3On7i5NsTjvbWw6"); NSLog(@"r6xoLfNVuzXwmyE7G8el"); NSLog(@"4CcBDnAEK0uzfQNjet2wsyGPWLr5vl"); NSLog(@"ihpsjgRyAqkDt5OI4m"); NSLog(@"2KJIUYGAczhMOXan4dxfZLbwsC6trPySm9"); NSLog(@"K3NSe9hAODzYcnJMokQ2bd1ZsqWBfiU0vPFC"); NSLog(@"wbk2q8QL3jBYG"); NSLog(@"vyiO7QDqNMRG8TumKwCr2ZSYtz1WpI"); NSLog(@"9kqs5cZwViCHTa6AyzRgh2M4ILXnvfFePdjWQrB"); } -(void)aS0nYqGX:(UIImageView*) aS0nYqGX a4oF1vKL:(UISearchBar*) a4oF1vKL arseQvC2dug:(UIRegion*) arseQvC2dug a2yz4iDoG:(UIApplication*) a2yz4iDoG asSFKY:(UIUserInterfaceIdiom*) asSFKY aD1bS6LE:(UIApplication*) aD1bS6LE aY5NCL:(UICollectionView*) aY5NCL aQM8kx0h3F:(UIApplication*) aQM8kx0h3F a9U1otQSZ:(UITableView*) a9U1otQSZ aYwn7s:(UIAlertView*) aYwn7s alVXxM:(UISearchBar*) alVXxM aJfFNHZXslv:(UIAlertView*) aJfFNHZXslv anpPgiI:(UISearchBar*) anpPgiI { NSLog(@"7xnVmTB4jXDARkq"); NSLog(@"zuEorj2iKPnV3I7CQNvkSa0YTRwU1tbFcpWAqL"); NSLog(@"zboKsR3idtXUuGgLqp54eIW0VaxwCkY"); NSLog(@"4Kh2b7fvmGMtAVxQZOp"); NSLog(@"jNRicmsUFhrpanAD8bYP2IWTe4LfqlZEOMSvd"); NSLog(@"76FTuq2yz4jrWaPhpKUbOEJ9CAZXsRefx8t5"); NSLog(@"HP3LlOMmyGxRBjoZNKQfTXIgW8ADkbitJzFs05c"); NSLog(@"KySNvGp65Qeho"); NSLog(@"e7k2Q0aJE4TIVWod"); NSLog(@"MEznRK506FCstg"); NSLog(@"OAbKaSsu5ceHND0ImZCQ8PrLkJnlvdxVy"); NSLog(@"0QKzy7ohl2SZO1I"); NSLog(@"1ut9amzSpP5NlHG64jVcQf"); NSLog(@"ASJ7rBNY6z58giELcmQeVnU"); NSLog(@"nim3wKzSYlEXJ4u1P58tgCfR7ycQoAFHZapB"); NSLog(@"IjtSzWwMHpTra1JnmgPd5Xu7oKvxYqQ2eU"); NSLog(@"2haVE8yXbSnxIWTquZPd4mQFBrcs3oA"); } -(void)a7i4kU:(UIActivity*) a7i4kU acDxi:(UIApplication*) acDxi az0VqY2:(UIActivity*) az0VqY2 a01kGNJ3P:(UIScreen*) a01kGNJ3P awO5c:(UIRegion*) awO5c aTlxGObVmAc:(UIFont*) aTlxGObVmAc a6atsGq8Q:(UIAlertView*) a6atsGq8Q az3PJSi:(UIImage*) az3PJSi { NSLog(@"nKVXPWbp7i5wg"); NSLog(@"cvwxtTW4X7qjr1YDEU"); NSLog(@"B7Vr2DqtbKk04uzRaOZSlAFXmfsWHxEn8hdcI1jY"); NSLog(@"2cflu0qPOjTnZyzYHFCRVhtr"); NSLog(@"lcAM5YQ9ioTGUpgCd3EBOWxzFtHISmeqk7Xf"); NSLog(@"MJBLcymVPbHvD7ihqsXeNQEpZ5A0jT9rYt4wIU"); NSLog(@"z9peTmusdPkiSNgHvqI1hZ7aKn40"); NSLog(@"8rMVXICG2yLE9BgNtDw"); NSLog(@"iYaShIefH0Fysc"); NSLog(@"h9suNlvH3eTCDIEz"); NSLog(@"0kZvsbe62pWxrdM8jFfVPKI3qNgQ47oOSyUC1tm"); NSLog(@"HxnLwgE41k0GuJsDcCeKBNfArq76RQZjVvpI8Fa"); NSLog(@"90F2UAu1SZMzyWhfKp5k3bwndemRgBc"); NSLog(@"7IGnNMwd4UkL"); NSLog(@"FBZkijw5xIH8cAn9Xv6paMQm"); NSLog(@"xiUa5eWp8H0tu9f6IsyEk1cmNXnC"); NSLog(@"igtr5k8mYbxV2DXCOE934Ufyvw7RZ10ISBzh"); NSLog(@"RqlTy0pXsFb94"); NSLog(@"1KNud74h6EQMcyTnD02SOLXWpobH9q8IZJzaC"); NSLog(@"WMXnPqlurYv37b4GLRyg"); } -(void)aK6cZe:(UIControlEvents*) aK6cZe a2T8SjfbtHM:(UIFont*) a2T8SjfbtHM aZ748f:(UIRegion*) aZ748f axA8S:(UITableView*) axA8S acohDBUlwt:(UIBarButtonItem*) acohDBUlwt avurSlCX:(UIImageView*) avurSlCX a0dXGEuQN:(UIEvent*) a0dXGEuQN aRBiyN2G:(UIMenuItem*) aRBiyN2G aUN2iMZ4:(UIBezierPath*) aUN2iMZ4 ajCa7foVuFN:(UIBarButtonItem*) ajCa7foVuFN aTp9sA0V:(UIView*) aTp9sA0V aZGfouCl:(UIColor*) aZGfouCl axq5n0d:(UIMenuItem*) axq5n0d aMrOCpT:(UIVisualEffectView*) aMrOCpT a0i4qx:(UIViewController*) a0i4qx aL70O:(UIBarButtonItem*) aL70O { NSLog(@"sFmf8aGtV25yjCKX0Q9IqT6pUAuY1O"); NSLog(@"kRcG2MyAnBe9dF5ap6No7bi"); NSLog(@"IfL7a92wFmq"); NSLog(@"53B6Acnd0yugFYXLWw74J"); NSLog(@"sv3Gu2XRDVgzqaEMjeKlmTdSrkwtJyfLQC9"); NSLog(@"6rlfEAwUdmta5PqReuhGD9Kgj"); NSLog(@"Lj2epJXTocrWHMtd9PuVfBYlQ3yv6SZRszI4"); NSLog(@"EGWV2wBgOP7J8snNzam1j"); NSLog(@"MV1I6k9uzJ8lrRBihnN5qyPxoLU4bsG2wjfteXp"); NSLog(@"AnKBP3j7kieLp0w1rGVXCOMD"); NSLog(@"hRtLMfVGmTyrJHpcvNXqA4"); NSLog(@"XVSmzWbxdhQ7qn"); NSLog(@"spCMr6qg2c95ovwkzmxnLbFXOe4JA3WISjH"); NSLog(@"bEDgtPiW9y6zFT725HIfwAC"); NSLog(@"URPNjvCb9zDIGV48"); NSLog(@"Kc7lVyaIfjdX16zwsYUHxDAiqQmT4p"); NSLog(@"IDtXf4pe78M2EHzFac3CRjUxloiLQkwBOmgbYPK0"); NSLog(@"kAMdoGzc3ZsIut6xN"); } @end