UITextField验证视觉反馈 [英] UITextField Validation visual feedback

查看:125
本文介绍了UITextField验证视觉反馈的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个uiTextField我正在验证输入,当我输入无效时,有什么方法可以显示输入无效?是否存在显示无效输入状态的内置机制?

i have a uiTextField that i am validating input on, when i have invalid input what are some appropriate ways to show that the input is invalid? is there any built in mechanism for showing invalid input states?

推荐答案

向左侧添加警告图像非常容易UITextField的-hand侧表示该字段需要一个值。

It's pretty easy to add an 'warning' image to the left-hand side of a UITextField to indicate that the field needs a value.

试试这个:

UITextField* field = .... your text field ...

if ( fails_validation ) {
  field.leftViewMode = UITextFieldViewModeAlways;
  UIImageView* imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 32, 32)];
  imageView.image = [UIImage imageNamed:@"warning.png"];
  imageView.contentMode = UIViewContentModeScaleAspectFit;
  field.leftView = imageView;
} else {
  field.leftViewMode = UITextFieldViewModeNever;
  field.leftView = nil;
}

这篇关于UITextField验证视觉反馈的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆