How to set the border of UITextView to same as border color of UITextField

n179911 picture n179911 · Sep 21, 2014 · Viewed 43.8k times · Source

By default UITextField has a light gray color as its border color. I want to set my UITextView to have the same border color as the UITextField.

I tried:

myTextView.layer.borderColor = UIColor.lightGrayColor().CGColor
or
myTextView.layer.borderColor = UIColor.lightTextColor().CGColor
or 
myTextView.layer.borderColor = myTextField.layer.borderColor

They still have up to have different color. Can you please tell me how to see teh UITextView border to match UITextField color?

Thank you.

Answer

Deepak picture Deepak · Sep 22, 2014

Try this code.

UIColor *borderColor = [UIColor colorWithRed:204.0/255.0 green:204.0/255.0 blue:204.0/255.0 alpha:1.0];

myTextView.layer.borderColor = borderColor.CGColor;
myTextView.layer.borderWidth = 1.0;
myTextView.layer.cornerRadius = 5.0;

change borderWidth and cornerRadius value to get exact ui as UITextField.