0

After successfully modifying the colours of my UIAlertController, I looked to doing the same for the UITextField inside that same UIAlertController. However, a white "outer border" appears around the UITextField, with the border colour I set visible inside that "outer border".

What I want is for that white "outer border" to be clear/the same colour as the UIAlertController view background.

My current code:

addAlert.addTextField(configurationHandler: { (textField) -> Void in
            textField.placeholder = "ABC 123"
            textField.textAlignment = .left
            textField.backgroundColor = Theme.current.barColor
            textField.textColor = Theme.current.titleColor
            textField.attributedPlaceholder = NSAttributedString(string: "ABC 123", attributes: [NSAttributedStringKey.font : UIFont.systemFont(ofSize: 14, weight: .regular), NSAttributedStringKey.foregroundColor : Theme.current.subTitleColor])
            textField.layer.borderWidth = 1.0
            textField.layer.borderColor = Theme.current.subTitleColor.cgColor
            textField.layer.backgroundColor = Theme.current.barColor.cgColor
        })

Screenshot of the UIAlertController:

enter image description here

Thank you in advance!

podomunro
  • 495
  • 4
  • 16
  • 1
    I'd suggest to use your own alert view instead of trying to customize the `UIAlertController`. It's not done for customization. – Larme Jul 01 '18 at 20:51

1 Answers1

0

I was able to remove the white "outer border" by running this code AFTER the alert is presented:

for textField in addAlert.textFields! {
    let container = textField.superview
    let effectView = container?.superview?.subviews[0]

    if (effectView as? UIVisualEffectView) != nil {
        container?.backgroundColor = .clear
        effectView?.removeFromSuperview()
    }
}

This is a Swift conversion of Rory's answer to another question

podomunro
  • 495
  • 4
  • 16