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

5 Solutions Collect From Internet About “How to set the border of UITextView to same as border color of UITextField”

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.

This Swift code also works for setting same border color, width & radius as UITextField:

myTextView.layer.borderColor = UIColor(red: 0.9, green: 0.9, blue: 0.9, alpha: 1.0).CGColor
myTextView.layer.borderWidth = 1.0
myTextView.layer.cornerRadius = 5

I had this similar question for iOS 10, and wasn’t able to find an answer, but this is what I found using the Digital Color Meter in Utilities and the iOS Simulator.

Swift 3 / iOS 10

let color = UIColor(red: 186/255, green: 186/255, blue: 186/255, alpha: 1.0).cgColor
myTextView.layer.borderColor = color
myTextView.layer.borderWidth = 0.5
myTextView.layer.cornerRadius = 5

The exact color is:

Objective-C:

[UIColor colorWithRed:0.76 green:0.76 blue:0.76 alpha:1.0].CGColor;

Swift:

UIColor(red:0.76, green:0.76, blue:0.76, alpha:1.0).CGColor

Try this code for Swift

let borderColor = UIColor.whiteColor.Cgcolor()

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