Search code examples
iosswiftuitextview

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


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.

How to set the UITextView border to match UITextField color?


Solution

  • 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.