4

谁能建议我如何创建一个 4 位数的密码输入屏幕,例如一次性密码,用户将输入,一个圆圈将被检查/变暗。

我知道我可以通过使用图像和隐藏文本字段来创建它。但我无法决定最好的方法。

任何帮助将不胜感激。

4

2 回答 2

3

想象一下你有一个UITextField. 让用户的输入显示为黑点(而不是暴露他们的信息)就像这样做一样简单(假设UITextField被调用field,并且您使用的是 Swift)。

field.secureTextEntry = true

老实说,我不完全确定你在问什么,但这是我最好的猜测。

于 2015-12-19T06:14:34.687 回答
0

我最好的猜测是使用图像来实现这一点。您可以简单地在 UITextField 的子视图上添加图像。

 func addImageToTextField(txtPin : UITextField)
    {
        let imageView = UIImageView();

        let image = UIImage(named: "darkImage.png");

        imageView.image = image;

        imageView.frame = CGRect(x: 0, y: 0, width: txtPin.frame.width, height: txtPin.frame.height)

        txtPin.addSubview(imageView)

    }

并从textFieldshouldChangeCharactersInRange

func textField(textField: UITextField, shouldChangeCharactersInRange range: NSRange, replacementString string: String) -> Bool {

        textField.textColor = UIColor.clearColor()
        if (!string.isEmpty) {

            self.addImageToTextField(textField)
         }

同样,如果用户点击后退按钮来清除文本字段,您也可以这样做

我已经这样做了,对我来说就像一个魅力。干杯!!快乐编码。

于 2015-12-19T07:56:02.693 回答