UIAlertViewController中的文本字段具有圆角矩形边框样式。 (迅速)

时间:2015-01-09 12:42:17

标签: swift ios8 xcode6 uialertview

将文本字段添加到UIAlertController没有问题,但我发现这些文本字段很可怕。有谁知道如何让它们更具吸引力?

我添加文字字段的代码:

let pincodeAlert:UIAlertController = UIAlertController(title: alertTitle, message: "Enter your passcode", preferredStyle: UIAlertControllerStyle.Alert)
pincodeAlert.addTextFieldWithConfigurationHandler({ (pinCodeTextField:UITextField!) -> Void in
            pinCodeTextField.placeholder = "Password"
            pinCodeTextField.secureTextEntry = true
pincodeAlert.addAction(UIAlertAction(title: "Cancel", style: UIAlertActionStyle.Cancel, handler: nil}))
pincodeAlert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: { (action) -> Void in
            //do some other stuff here...
        }))
presentViewController(pincodeAlert, animated: true, completion: nil) 

我当前的提醒视图的文本字段非常方形,看起来不太好。

我想要的是什么:

enter image description here

我有什么:

enter image description here

2 个答案:

答案 0 :(得分:0)

设置alertViewStyle。

alert.alertViewStyle = UIAlertViewStyle.LoginAndPasswordInput

答案 1 :(得分:0)

您需要在PIN码字段中设置边框样式;

            pinCodeTextField.borderStyle = UITextBorderStyleRoundedRect
            pinCodeTextField.placeholder = "Password"
            pinCodeTextField.secureTextEntry = true

我还遇到了黑色边框的问题,如果你有同样的问题,请看看这个答案;

UITextField in UIAlertController (border, backgroundColor)