Remove rounded corners from text field, keep background opacity iOS Swift

3.8k views Asked by At

In Xcode 6.3, on creating a text view, there are 4 options given for the border style.

enter image description here

The rounded corner border style provides the option of changing the opacity of the background (not the text).

The square corner border style's alpha value only changes the opacity of the text, and not the background of the text field.

How do I have a square-cornered text field with a 0.5 Alpha value for background opacity, but a 0.0 Alpha Value for text opacity?

1

There are 1 answers

0
simons On BEST ANSWER

You can set any combination you want programmatically. Eg:

override func viewDidLoad() {
    super.viewDidLoad()

    let backColor = UIColor(red: 0, green: 0, blue: 0, alpha: 0.5)
    myTextField.backgroundColor = backColor

    let textColor = UIColor(red: 0, green: 0, blue: 0, alpha: 0.5)
    myTextField.textColor = textColor

}

You could also set the background or text color to Clear Color in the Attributes inspector.