第一步:
_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]; } }
和简单,仅做记录!