How to increase the distance between textFields in UIAlertController in Xcode (Swift)?

func showAlert() { let alert: UIAlertController = UIAlertController(title: "Enter name", message: "Enter name", preferredStyle: .alert) alert.addTextField { (textField) in textField.placeholder = "name" } alert.addTextField { (textField) in textField.placeholder = "address" textField.isEnabled = false } let OKAction = UIAlertAction(title: "OK", style: .default) { action in } let cancelAction = UIAlertAction(title: "Cancel", style: .default) { action in } alert.addAction(cancelAction) alert.addAction(OKAction) self.present(alert, animated: true, completion: nil) } 

enter image description here

    1 answer 1

    In general, you need to add for each textField this line textField.borderStyle = UITextBorderStyle.roundedRect , since for rounded textField the distance between them is greater. Next, to remove a table that contains textFields, you need to add code after self.present(alert, animated: true, completion: nil)

     func showAlert() { let alert: UIAlertController = UIAlertController(title: "Enter name", message: "Enter name", preferredStyle: .alert) alert.addTextField { (textField) in textField.placeholder = "name" textField.borderStyle = UITextBorderStyle.roundedRect } alert.addTextField { (textField) in textField.placeholder = "address" textField.borderStyle = UITextBorderStyle.roundedRect textField.isEnabled = false } let OKAction = UIAlertAction(title: "OK", style: .default) { action in let name = alert.textFields?.first?.text } let cancelAction = UIAlertAction(title: "Cancel", style: .default) { action in } alert.addAction(cancelAction) alert.addAction(OKAction) self.present(alert, animated: true, completion: nil) for textField in alert.textFields! { let container = textField.superview let effectView = container?.superview?.subviews[0] if (effectView != nil) { container?.backgroundColor = UIColor.clear effectView?.removeFromSuperview() } } } 

    enter image description here .