Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITextField backgroundColor set in Interface Builder is nil at runtime in iOS 14

I have an app that works properly on iOS 11-13, but when I run it in iOS 14 several text fields within it are rendered with a nil, and so transparent, background color even though the background color is set to White explicitly in the Interface Builder.

I can't see anywhere in the code that uses those text fields that might mess up the background color, and these same UITextFields running under the same scenarios appear with White background on iOS 13 and below.

If I set the color explicitly in code everything works fine in iOS 14

nameTextField.backgroundColor = .white

I don't want to add redundant code just to reset the background color. Is there anything I might be missing about new UITextField behaviour in iOS 14?

like image 592
Avihu Turzion Avatar asked Jul 13 '20 14:07

Avihu Turzion


People also ask

How can I tell if TextField is edited?

Ctrl + Click on the textfield in interface builder. Drag from EditingChanged to inside your view controller class in the assistant view. Name your function ("textDidChange" for example) and click connect.

How can I change background color in Stackview?

You can't do this – UIStackView is a non-drawing view, meaning that drawRect() is never called and its background color is ignored. If you desperately want a background color, consider placing the stack view inside another UIView and giving that view a background color. Reference from HERE.

How set TextField text in Swift?

To do the inverse, String to Int (say you want to take the value a user has typed in), you can do the following: if let myInt = yourTextField. text. toInt() { VAT = myInt; } else { // Show some error to the user. }

How do I change TextField background color in Swiftui?

TextField view doesn't provide a way to add background color but we can use the background modifier to add color to the TextField.


1 Answers

Going through the storyboards and resetting the background color of the text fields did the trick for me in Xcode 12 GM.

like image 96
Evtim Georgiev Avatar answered Sep 19 '22 13:09

Evtim Georgiev