Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS: How do I make my UITextfield highlight when tapped?

Do I have to do this with code or is there something in the inspector that I'm missing?

like image 767
TWcode Avatar asked Dec 27 '22 14:12

TWcode


1 Answers

Unlike UIButton, a UITextField does not have a highlighted state. If you want to change the color of the textfield when it receives focus, you can use the UITextFieldDelegate's

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField

This will be called when the control first receives focus. From there you can change the background and/or text color. Once focus leaves the control, you can use

- (BOOL)textFieldShouldEndEditing:(UITextField *)textField

to reset the colors.

like image 126
memmons Avatar answered Feb 16 '23 08:02

memmons