Change UITextField’s bottom line color change on change of editing status?

INTRODUCTION
UITextField is used for input entry field item and take input from user. In UITextField there is default property named placeholder which on start of editing in UITextFiled disappears and if it is leaved blank then it comes up showing again just like there are many animation you can perform while start of UITextField editing and in end of editing methods.

UITextFields’s Bottom Line UIView Colour – OVERVIEW

For this you should have basic idea about UITextField and its delegates methods. If you want to read about it then click here <https://developer.apple.com/documentation/uikit/uitextfield>

Solution For Changing UITextField’s Bottom Line View Colour on Selection and return

STEP 1. Add UITextField in your UIViewController and then create and connect IBOutlet with it. After this add UIView and place it just below UITextField with heigh constant 1 or you what you like to keep it and add other constraints as it look like horizontal line below.

IBOutlet UITextField *txtField;
IBOutlet UIView *lineView;

STEP 2. Add UITextFieldDelegate in your UIViewController then after this add its delegation methods and add below codes

- (void)textFieldDidBeginEditing:(UITextField *)textField
{
[self didBeginEditingIn:textField];
[lineView setBackgroundColor: [UIColor redColor]];
}

- (void)textFieldDidEndEditing:(UITextField *)textField
{
[self didEndEditing];
[lineView setBackgroundColor: [UIColor blackColor]];
}

In this delegates methods in textFieldDidBeginEditing method it will called when used taps on UITextField and it start begin editing and that moment bottom line will change colour due code added in this method when user taps on another UITextField or return keyboard then textFieldDidEndEditing method called and code written in this make bottom line colour as it was defaultly when app started.

Leave a Comment