iOS UITextField或UITextView的内容是否为空

简介:

//判断正在编辑的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;

}










本文转自 卓行天下  51CTO博客,原文链接:http://blog.51cto.com/9951038/1758334,如需转载请自行联系原作者
目录
相关文章
|
iOS开发
iOS开发 - UITableView的tableHeaderView注意事项(遮挡cell,内容重复等等)
iOS开发 - UITableView的tableHeaderView注意事项(遮挡cell,内容重复等等)
271 0
iOS-UITextView设置行间距,内容颜色(变相设置类似UITextField的placeholder)
iOS-UITextView设置行间距,内容颜色(变相设置类似UITextField的placeholder)
276 0
iOS-UITextView设置行间距,内容颜色(变相设置类似UITextField的placeholder)
|
iOS开发
IOS——UITextField自动适应键盘弹出
IOS——UITextField自动适应键盘弹出
145 0
|
Web App开发 前端开发 JavaScript
解决 input 输入框在 iOS 系统中无法输入内容
解决 input 输入框在 iOS 系统中无法输入内容
623 0
|
程序员 API iOS开发
iOS开发:字符串设置指定内容的文字颜色、文字大小、文字字体类型
在iOS开发过程中,会有一些为了提高APP的视觉效果而设置的特别一点的效果,比如一行文字需要自定义不同的颜色和文字大小,这就用到通过富文本来设置字符串的颜色、大小和文字类型。这篇博文我打算只介绍怎么设置指定内容的一些文字属性设置,如果之前看过我写的博文,就会发现有一篇类似介绍通过富文本来设置字符串内容的博文,但是那篇是综合性的,包括介绍button的,以及UItextfield的设置,所以在这里我只介绍怎么设置字符串指定位置的一些自定义设置的方法,如有不妥之处,欢迎指正。
532 0
|
存储 安全 搜索推荐
iOS逆向-day1:逆向内容的简介与越狱环境搭建
iOS逆向-day1:逆向内容的简介与越狱环境搭建
349 0
iOS逆向-day1:逆向内容的简介与越狱环境搭建
|
iOS开发
iOS 让tabbr背景透明看到页面内容的方法
iOS 让tabbr背景透明看到页面内容的方法
465 0
|
iOS开发
iOS UITextField rightView覆盖clearButton的解决办法
iOS UITextField rightView覆盖clearButton的解决办法
519 0
|
iOS开发
iOS UITextField(编辑框)
UITextField属性 0.enablesReturnKeyAutomatically 默认为No,如果设置为Yes,文本框中没有输入任何字符的话,右下角的返回按钮是disabled的。
1131 0
|
自然语言处理 iOS开发 索引
iOS智能地处理用户的输入内容(处理语言工具CFStringTransform 的应用)
iOS智能地处理用户的输入内容(处理语言工具CFStringTransform 的应用)
223 0
iOS智能地处理用户的输入内容(处理语言工具CFStringTransform 的应用)