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
.
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
#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;
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With