我的问题是我希望像WhatsApp验证码textField一样UITextField
(如下图所示)。默认值包含要输入的字符数(作为用户提示)。当用户输入文字时,逐个用输入的字符替换提示字符?
非常感谢任何帮助。
答案 0 :(得分:1)
请参阅我之前回答的以下链接。希望您能了解如何做到这一点。只有一个UITextField
,没有使用第三方库。
链接 - https://stackoverflow.com/a/36769911/5097148
不要使用粘贴进行一些更改 -
在myLable
上方添加textField
,然后在viewDidLoad()
self.myLable.userInteractionEnabled=true;
UITapGestureRecognizer *LongPressgesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapPressgesture:)];
tapPressgesture.delegate=self;
[self.myLable addGestureRecognizer:tapPressgesture];
和
- (void)tapPressgesture:(UITapPressGestureRecognizer *)recognizer
{
[self.txtField becomeFirstResponder];
}
对于像您的图像这样的背景,您可以设置textField背景图片属性或为文本字段添加底部边框。 UITextField
边框样式必须为UITextBorderStyleNone
如果您有任何问题,请告知我们。
快乐编码:)
答案 1 :(得分:0)
添加6个Textfields和背景图片后。
-(BOOL)textFieldShouldReturn:(UITextField *)textField {
return YES;
}
-(void)textFieldDidEndEditing:(UITextField *)textField{
if (textField==textfield1)
{
[textfield1 resignFirstResponder];
[textField2 becomeFirstResponder];
}
else if (textField==textfield2)
{
[textfield2 resignFirstResponder];
[textField3 becomeFirstResponder];
}
}
继续直到textfield 6