Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing textField border color iOS [duplicate]

I want to change UITextField border color. Is it possible to customize the color of border? I searched all options in xib but I did not found any option to change border color.

like image 377
user2017285 Avatar asked Mar 01 '13 07:03

user2017285


3 Answers

you can use this:

yourTextField.layer.borderColor=[[UIColor blackColor]CGColor];

yourTextField.layer.borderWidth=1.0;

and remember to import #import <QuartzCore/QuartzCore.h> in your .h file

You can also specify your RGB value.

yourTextField.layer.borderColor=[[UIColor colorWithRed:178.0f/255.0f green:178.0f/255.0f blue:178.0f/255.0f alpha:1.0] CGColor];

Note: you need to set both values starting with iOS 7

Update for swift 2.3

yourTextField.layer.borderColor = UIColor.blackColor().CGColor
yourTextField.layer.borderWidth = 1.0

OR

yourTextField.layer.borderColor = UIColor(red: 178.0 / 255.0, green: 178.0 / 255.0, blue: 178.0 / 255.0, alpha: 1.0).CGColor

Update for swift 3.1.1

yourTextField.layer.borderColor = UIColor.black.cgColor
yourTextField.layer.borderWidth = 1.0

OR

yourTextField.layer.borderColor = UIColor(red: 178.0 / 255.0, green: 178.0 / 255.0, blue: 178.0 / 255.0, alpha: 1.0).cgColor
like image 58
KDeogharkar Avatar answered Nov 13 '22 05:11

KDeogharkar


#import <QuartzCore/QuartzCore.h>

Use below code to change Textfield's border color

textField.layer.borderWidth = 2.0f;
textField.layer.borderColor = [[UIColor redColor] CGColor];
textField.layer.cornerRadius = 5;
textField.clipsToBounds      = YES;

For SWIFT:

textField.layer.borderColor = UIColor.redColor().CGColor;
like image 30
Nazir Avatar answered Nov 13 '22 05:11

Nazir


Use Quartzcore framework. You can set the textField.layer.borderWidth, as well as borderColor:

tField.layer.borderColor = [UIColor redColor].CGColor;

for more reference: https://stackoverflow.com/a/5749376/1554632

like image 22
Nikita P Avatar answered Nov 13 '22 04:11

Nikita P