Add border at bottom of TextField in iOS

If you want to make your TextField simple like in Android Lollipop. In this code, your TextField will be clean with a single border at bottom and your placeholder/text. Checkout the below image for that.

Screen Shot 2015-12-31 at 7.35.57 PM

Just add this code in your app and you are ready to go.

textField.backgroundColor=[UIColor clearColor];
textField.borderStyle = UITextBorderStyleNone;
[textField setValue:[UIColor whiteColor] forKeyPath:@"_placeholderLabel.textColor"];
CALayer *bottomBorder = [CALayer layer];
bottomBorder.frame = CGRectMake(0, textField.frame.size.height - 2, textField.frame.size.width, 2.0f);
bottomBorder.backgroundColor = [[UIColor whiteColor]CGColor];

[textField.layer addSublayer:bottomBorder];

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s