iOS UITextField或UITextView的内容是否为空
2016-03-30 11:20
477 查看
//判断正在编辑的UITextField或UITextView的内容是否为空,判断正在编辑的UITextField或UITextView的内容是否为空,以此来控制button的点亮状态#pragma mark- UITextFieldDelegate- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{ NSMutableString * changedString=[[NSMutableString alloc]initWithString:textField.text]; [changedString replaceCharactersInRange:range withString:string]; if (changedString.length!=0) { self.navigationItem.rightBarButtonItem.enabled=YES; }else{ self.navigationItem.rightBarButtonItem.enabled=NO; }
return YES;}
#pragma mark- UITextViewDelegate- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString*)text{ NSMutableString * changedString=[[NSMutableString alloc]initWithString:textView.text]; [changedString replaceCharactersInRange:range withString:text]; if (changedString.length!=0) { self.navigationItem.rightBarButtonItem.enabled=YES; }else{ self.navigationItem.rightBarButtonItem.enabled=NO; } return YES;}
//一些判断技巧
- (BOOL)verifyData{ if(tfPostName.text.length<1){ //01 tfPostName.layer.borderColor = [UIColor redColor].CGColor; tfPostName.layer.borderWidth =1.0; tfPostName.layer.cornerRadius =5.0; return NO; } else if (tfPositionType.text.length<1){ //02 tfPositionType.layer.borderColor = [UIColor redColor].CGColor; tfPositionType.layer.borderWidth =1.0; tfPositionType.layer.cornerRadius =5.0; return NO; } else if ( tfPeopleNum.text.length<1){ //03 tfPeopleNum.layer.borderColor = [UIColor redColor].CGColor; tfPeopleNum.layer.borderWidth =1.0; tfPeopleNum.layer.cornerRadius =5.0; return NO; } else if ( tfWages.text.length<1){ //04 tfWages.layer.borderColor = [UIColor redColor].CGColor; tfWages.layer.borderWidth =1.0; tfWages.layer.cornerRadius =5.0; return NO; }else if (tfUnit.text.length<1){ //05 tfUnit.layer.borderColor = [UIColor redColor].CGColor; tfUnit.layer.borderWidth =1.0; tfUnit.layer.cornerRadius =5.0; return NO; }else if (tfStartDate.text.length<1){ //07 tfStartDate.layer.borderColor = [UIColor redColor].CGColor; tfStartDate.layer.borderWidth =1.0; tfStartDate.layer.cornerRadius =5.0; return NO; }else if (tfEndDate.text.length<1){ //08 tfEndDate.layer.borderColor = [UIColor redColor].CGColor; tfEndDate.layer.borderWidth =1.0; tfEndDate.layer.cornerRadius =5.0; return NO; }else if (tfSescribe.text.length<1){ //09 tfSescribe.layer.borderColor = [UIColor redColor].CGColor; tfSescribe.layer.borderWidth =1.0; tfSescribe.layer.cornerRadius =5.0; //tfSescribe.text.length == 0; return NO; }
// }else if (tfPayWay.text.length<1){ //tfSescribe // //10--// tfPayWay.layer.borderColor = [UIColor redColor].CGColor;// tfPayWay.layer.borderWidth =1.0;// tfPayWay.layer.cornerRadius =5.0;// return NO;// // } else if (tfContactPerson.text.length<1){ //11 tfContactPerson.layer.borderColor = [UIColor redColor].CGColor; tfContactPerson.layer.borderWidth =1.0; tfContactPerson.layer.cornerRadius =5.0; return NO; } else if ( tfContactPhone.text.length<1){ //12-- tfContactPhone.layer.borderColor = [UIColor redColor].CGColor; tfContactPhone.layer.borderWidth =1.0; tfContactPhone.layer.cornerRadius =5.0; return NO; }else if (tfJobArea.text.length<1){ //13 tfJobArea.layer.borderColor = [UIColor redColor].CGColor; tfJobArea.layer.borderWidth =1.0; tfJobArea.layer.cornerRadius =5.0; return NO; } else if (tfDetailAddress.text.length<1){ //14-- tfDetailAddress.layer.borderColor = [UIColor redColor].CGColor; tfDetailAddress.layer.borderWidth =1.0; tfDetailAddress.layer.cornerRadius =5.0; return NO; }else if (tfUnit.text.length<1){ //15 tfUnit.layer.borderColor = [UIColor redColor].CGColor; tfUnit.layer.borderWidth =1.0; tfUnit.layer.cornerRadius =5.0; return NO; } else { return YES; } }
//岗位描述不能为空的判断#pragma mark- UITextViewDelegate- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{ NSMutableString * changedString=[[NSMutableString alloc]initWithString:tfSescribe.text]; [changedString replaceCharactersInRange:range withString:text]; if (changedString.length<1) { //self.navigationItem.rightBarButtonItem.enabled=YES; [CMNavBarNotificationView notifyWithText:@"" andDetail:@"请完善发布信息"]; }else{ //self.navigationItem.rightBarButtonItem.enabled=NO; //[CMNavBarNotificationView notifyWithText:@"" andDetail:@"请完善发布信息"]; } return YES;}
return YES;}
#pragma mark- UITextViewDelegate- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString*)text{ NSMutableString * changedString=[[NSMutableString alloc]initWithString:textView.text]; [changedString replaceCharactersInRange:range withString:text]; if (changedString.length!=0) { self.navigationItem.rightBarButtonItem.enabled=YES; }else{ self.navigationItem.rightBarButtonItem.enabled=NO; } return YES;}
//一些判断技巧
- (BOOL)verifyData{ if(tfPostName.text.length<1){ //01 tfPostName.layer.borderColor = [UIColor redColor].CGColor; tfPostName.layer.borderWidth =1.0; tfPostName.layer.cornerRadius =5.0; return NO; } else if (tfPositionType.text.length<1){ //02 tfPositionType.layer.borderColor = [UIColor redColor].CGColor; tfPositionType.layer.borderWidth =1.0; tfPositionType.layer.cornerRadius =5.0; return NO; } else if ( tfPeopleNum.text.length<1){ //03 tfPeopleNum.layer.borderColor = [UIColor redColor].CGColor; tfPeopleNum.layer.borderWidth =1.0; tfPeopleNum.layer.cornerRadius =5.0; return NO; } else if ( tfWages.text.length<1){ //04 tfWages.layer.borderColor = [UIColor redColor].CGColor; tfWages.layer.borderWidth =1.0; tfWages.layer.cornerRadius =5.0; return NO; }else if (tfUnit.text.length<1){ //05 tfUnit.layer.borderColor = [UIColor redColor].CGColor; tfUnit.layer.borderWidth =1.0; tfUnit.layer.cornerRadius =5.0; return NO; }else if (tfStartDate.text.length<1){ //07 tfStartDate.layer.borderColor = [UIColor redColor].CGColor; tfStartDate.layer.borderWidth =1.0; tfStartDate.layer.cornerRadius =5.0; return NO; }else if (tfEndDate.text.length<1){ //08 tfEndDate.layer.borderColor = [UIColor redColor].CGColor; tfEndDate.layer.borderWidth =1.0; tfEndDate.layer.cornerRadius =5.0; return NO; }else if (tfSescribe.text.length<1){ //09 tfSescribe.layer.borderColor = [UIColor redColor].CGColor; tfSescribe.layer.borderWidth =1.0; tfSescribe.layer.cornerRadius =5.0; //tfSescribe.text.length == 0; return NO; }
// }else if (tfPayWay.text.length<1){ //tfSescribe // //10--// tfPayWay.layer.borderColor = [UIColor redColor].CGColor;// tfPayWay.layer.borderWidth =1.0;// tfPayWay.layer.cornerRadius =5.0;// return NO;// // } else if (tfContactPerson.text.length<1){ //11 tfContactPerson.layer.borderColor = [UIColor redColor].CGColor; tfContactPerson.layer.borderWidth =1.0; tfContactPerson.layer.cornerRadius =5.0; return NO; } else if ( tfContactPhone.text.length<1){ //12-- tfContactPhone.layer.borderColor = [UIColor redColor].CGColor; tfContactPhone.layer.borderWidth =1.0; tfContactPhone.layer.cornerRadius =5.0; return NO; }else if (tfJobArea.text.length<1){ //13 tfJobArea.layer.borderColor = [UIColor redColor].CGColor; tfJobArea.layer.borderWidth =1.0; tfJobArea.layer.cornerRadius =5.0; return NO; } else if (tfDetailAddress.text.length<1){ //14-- tfDetailAddress.layer.borderColor = [UIColor redColor].CGColor; tfDetailAddress.layer.borderWidth =1.0; tfDetailAddress.layer.cornerRadius =5.0; return NO; }else if (tfUnit.text.length<1){ //15 tfUnit.layer.borderColor = [UIColor redColor].CGColor; tfUnit.layer.borderWidth =1.0; tfUnit.layer.cornerRadius =5.0; return NO; } else { return YES; } }
//岗位描述不能为空的判断#pragma mark- UITextViewDelegate- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{ NSMutableString * changedString=[[NSMutableString alloc]initWithString:tfSescribe.text]; [changedString replaceCharactersInRange:range withString:text]; if (changedString.length<1) { //self.navigationItem.rightBarButtonItem.enabled=YES; [CMNavBarNotificationView notifyWithText:@"" andDetail:@"请完善发布信息"]; }else{ //self.navigationItem.rightBarButtonItem.enabled=NO; //[CMNavBarNotificationView notifyWithText:@"" andDetail:@"请完善发布信息"]; } return YES;}
相关文章推荐
- 峰回路转,Firefox 浏览器即将重返 iOS 平台
- 峰回路转,Firefox 浏览器即将重返 iOS 平台
- 不可修补的 iOS 漏洞可能导致 iPhone 4s 到 iPhone X 永久越狱
- iOS 12.4 系统遭黑客破解,漏洞危及数百万用户
- 每日安全资讯:NSO,一家专业入侵 iPhone 的神秘公司
- [转][源代码]Comex公布JailbreakMe 3.0源代码
- 讲解iOS开发中基本的定位功能实现
- iOS中定位当前位置坐标及转换为火星坐标的方法
- js判断客户端是iOS还是Android等移动终端的方法
- iOS应用中UISearchDisplayController搜索效果的用法
- IOS开发环境windows化攻略
- iOS应用中UITableView左滑自定义选项及批量删除的实现
- 浅析iOS应用开发中线程间的通信与线程安全问题
- 检测iOS设备是否越狱的方法
- django自定义Field实现一个字段存储以逗号分隔的字符串
- .net平台推送ios消息的实现方法
- ThinkPHP CURD方法之field方法详解
- 探讨Android与iOS,我们将何去何从?
- Android、iOS和Windows Phone中的推送技术详解