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?
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.
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?
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: .
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.
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