zoukankan      html  css  js  c++  java
  • TextFiled的使用方法

    1.今天学习了textfiled的使用方法,在界面的设计中textfiled 使用的十分广泛:
    2.我们主要学习一下textfiled的代理方法:
    3.我们要设置textfiled 的代理方法和实现代理<uitextfiledDeegate>
    4.改变textfiled的背景颜色,实现方法如下:代理方法如下
    -(void)textFieldDidBeginEditing:(UITextField *)textField;

    #pragma mark -UITextFieldDelegate

    //开始编辑的时候

    -(void)textFieldDidBeginEditing:(UITextField *)textField

    {

        if(textField.tag ==0 ){

            textField.background = [UIImage imageNamed:@"enter.png"];

        }else if (textField.tag ==1){

            textField.background = [UIImage imageNamed:@"enter.png"];

        }else if (textField.tag ==2){

            textField.background = [UIImage imageNamed:@"enter.png"];

        }else if(textField.tag ==3){

            textField.background = [UIImage imageNamed:@"enter.png"];

        }

    }

     //结束编辑的时候

    -(void)textFieldDidEndEditing:(UITextField *)textField

    {

        if(textField.tag ==0 ){

            textField.background = [UIImage imageNamed:@"enter2.png"];

        }else if (textField.tag ==1){

            textField.background = [UIImage imageNamed:@"enter2.png"];

        }else if (textField.tag ==2){

            textField.background = [UIImage imageNamed:@"enter2.png"];

        }else if (textField.tag ==3){

            textField.background = [UIImage imageNamed:@"enter2.png"];

        }

    }

    5.textfiled代理的方法:限制输入文字的长度:
    -(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string;

    #pragma mark - UITextFiled 

    // 判断限制输入框的长度

    -(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{  

        NSString * toBeString = [textField.text stringByReplacingCharactersInRange:range withString:string]; //得到输入框的内容

        if (self.addressTF == textField)  //判断是否时我们想要限定的那个输入框

        {

            if ([toBeString length] > 50) { //如果输入框内容大于20则弹出警告

                textField.text = [toBeString substringToIndex:50];

                [MBProgressHUD showError:@"超过最大字数不能输入了"];

                return NO;

            }        }

        else if (self.nameTF == textField){

                if ([toBeString length]>20) {//如果输入框内容大于10弹出警告

                textField.text = [toBeString substringToIndex:20];

                [MBProgressHUD showError:@"超过最大字数不能输入了"];

                return NO;

            }

        }

        return YES;

    }




  • 相关阅读:
    SOD开源框架MSF(消息服务框架)介绍
    c#中foreach的一种用法
    MSSql异常处理框架
    什么是架构?有几人说的清楚
    MSSql动态行转列
    WebForm版demo,模拟手机Usb接口充电
    规范化流程不能窥探的咪咪
    我对领导者的定义
    以乞丐为最大的贵客
    程序猿,是如何逆袭的
  • 原文地址:https://www.cnblogs.com/zhufeng1994/p/4615877.html
Copyright © 2011-2022 走看看