0

I have a requirement that i need to add textfield on UIAlertController after alert message. I am using below code to achieve above requirement.

    *anAlertController.addTextField { (textField) in
        textField.allowsEditingTextAttributes = false
        textField.borderStyle = .none
        textField.layer.borderColor = UIColor.clear.cgColor
        textField.layer.borderWidth = 0.0
        textField.backgroundColor = UIColor.clear
        textField.textAlignment = NSTextAlignment.center
        textField.delegate = self
        textField.heightAnchor.constraint(equalToConstant: 50).isActive = true
        textField.text = "123456"
    }*

Above code is not removing border around textfield and not matching with alert background color. But if i try to add textfield to viewcontroller view with above code it is removing border padding. What wrong i am doing. Can you please anybody suggest how to achieve that

Rengers
  • 14,911
  • 1
  • 36
  • 54
Logger
  • 1,274
  • 1
  • 14
  • 25
  • Why you have tagged the question as objective-c, while the code written is in swift – Mahak Mittal Feb 05 '19 at 11:32
  • 1
    Check this link https://stackoverflow.com/questions/30040963/uitextfield-in-uialertcontroller-border-backgroundcolor/30225592 – Mahak Mittal Feb 05 '19 at 11:35
  • @MahakMittal Because if anybody knows in objective-c we can convert it to swift – Logger Feb 05 '19 at 11:37
  • @MahakMittal above link working properly. i tried it but i was placed above code before presenting the alert. Now i added above code after alert present. – Logger Feb 05 '19 at 11:41
  • Possible duplicate of [UITextField in UIAlertController (border, backgroundColor)](https://stackoverflow.com/questions/30040963/uitextfield-in-uialertcontroller-border-backgroundcolor) – Chetan Aug 27 '19 at 10:25

0 Answers0