3

I have no problem adding text fields to an UIAlertController but I find these text fields to be hideous. Does anyone know how to make them more appealing?

My code to add a text field:

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) 

My current alert view's text fields are very square and that does't look to well.

What I want:

enter image description here

What I have:

enter image description here

Petri
  • 1,020
  • 3
  • 14
  • 24

2 Answers2

0

Set your alertViewStyle.

alert.alertViewStyle = UIAlertViewStyle.LoginAndPasswordInput
Petri
  • 1,020
  • 3
  • 14
  • 24
0

You need to set the border style on the pin code field;

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

I also had an issue with a black border, if you have the same take a look at this answer;

UITextField in UIAlertController (border, backgroundColor)

Community
  • 1
  • 1
PaulB
  • 962
  • 7
  • 15