zoukankan      html  css  js  c++  java
  • ios开发之--通过通知监听textfield的输入状态,判断按钮的状态

    第一步:

    _rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _rightBtn.frame = CGRectMake(kWidth - 50-5, 7, kWidth - _tf.frame.size.width-10, 45);
        [_rightBtn setBackgroundImage:[UIImage imageNamed:@"send_un"] forState:UIControlStateNormal];
        [_rightBtn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
        [_inputView addSubview:_rightBtn];

    第二步:

        //监听textfield的输入状态
        [[NSNotificationCenter defaultCenter] addObserver:self
                                                 selector:@selector(textFieldDidChangeValue:)
                                                     name:UITextFieldTextDidChangeNotification
                                                   object:_tf];

    第三步:

    //这里可以通过发送object消息获取注册时指定的UITextField对象
    - (void)textFieldDidChangeValue:(NSNotification *)notification
    {
        UITextField *sender = (UITextField *)[notification object];
        if(sender.text.length != 0)
        {
            [_rightBtn setBackgroundImage:[UIImage imageNamed:@"send"] forState:UIControlStateNormal];
        }else
        {
            [_rightBtn setBackgroundImage:[UIImage imageNamed:@"send_un"] forState:UIControlStateNormal];
        }
    }

    和简单,仅做记录!

  • 相关阅读:
    十万个为什么
    安装VmwareTools遇到的问题
    CentOS7没有ifconfig命令怎么办
    ftp/ http/ https/ tcp的关系
    C/S和B/S架构
    Nginx 安装以及验证教程
    osi七层模型
    在linux上安装tenginx
    Awvs、Snort的下载安装
    Laravel——DI(依赖注入)
  • 原文地址:https://www.cnblogs.com/hero11223/p/7911258.html
Copyright © 2011-2022 走看看