I would like to programmatically specify the border radius of a UITextField
using Swift.
By default, a UITextField
has a slight border radius, however I would like to increase it and, after trawling through Interface Builder, I assume this can be done programmatically?
How to add border radius or rounded border to TextField or TextFormField. To add border radius or create rounded border around the TextField/TextFormField widget, add the decoration property and then use OutlineInputBorder widget. The OutlineInputBorder widget accepts the borderRadius parameter.
To get round corners button using Interface Builder add a Key Path = "layer. cornerRadius" with Type = "Number" and Value = "10" (or other value as required) in the " User Defined RunTime Attribute " of the Identity Inspector of the button.
You can round the corners of any SwiftUI view by using the cornerRadius() modifier. Simply add a value to the cornerRadius to control how rounded you want the view to be. Let us look at a simple example below. By adding a cornerRadius of 10 to our button we now get nice rounded corners on our button.
borderColor = (UIColor( red: 0.5, green: 0.5, blue:0, alpha: 1.0 )). CGColor; What I do in swift and what ALWAYS works: myTextField.
You can use:
nameOfTextField.layer.cornerRadius = 15.0 nameOfTextField.layer.borderWidth = 2.0 nameOfTextField.layer.borderColor = UIColor.red.cgColor
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