苹果在iOS 12,改进了一个很人性化的小细节。在做短信验证码功能的时候,自动获取短信中的验证码,然后点击填充即可。不用再向之前那样麻烦,自己看到弹出的短信信息后,死记硬背,再一个个敲上去,害怕背错了,还再验证一下。

  1、先设置textContentType属性,做好系统适配:

    UITextField *textField = [[UITextField alloc] init];

    if (@available(iOS 12.0, *)) {

        textField.textContentType = UITextContentTypeOneTimeCode;

    } else {

        // Fallback on earlier versions

    }

    [self.view addSubview:textField];

 

  2、让这个文本框成为第一响应者:

    [textField becomeFirstResponder];

相关文章:

  • 2022-12-23
  • 2021-12-09
  • 2021-06-20
  • 2022-12-23
  • 2022-12-23
  • 2022-01-19
  • 2022-01-01
  • 2021-06-25
猜你喜欢
  • 2021-09-24
  • 2021-11-27
  • 2022-12-23
  • 2022-12-23
  • 2021-12-31
  • 2021-07-08
相关资源
相似解决方案