Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 490
n179911 Avatar asked Sep 21 '14 18:09

n179911


People also ask

How do you put a border color on a storyboard?

borderColor needs a value with type CGColor . But only UIColor types can be set via Interface Builder's User Defined Runtime Attributes! So, you must set a UIColor to a proxy property via Interface Builder, then intercept that call to set the equivalent CGColor to the layer. borderColor property.

How to set border for textview in swift?

You can do this by choosing the assistant editor. Than control drag a line from the outlet in the code to the textfield. After the textfield is connected, you can add code to make a border in the viewDidLoad function. class ViewController: UIViewController { @IBOutlet var text : UITextField?

How do I create a rounded text field in Swift?

If you want to get the “rounded rect” text field style that we're used to with UITextField , you should use the . textFieldStyle(. roundedBorder)) modifier, like this: struct ContentView: View { @State private var name: String = "Tim" var body: some View { VStack(alignment: .


1 Answers

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.

like image 159
Deepak Avatar answered Sep 23 '22 19:09

Deepak