Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Specify border radius of UITextField in Swift

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?

like image 536
Daniel Bramhall Avatar asked Nov 30 '15 21:11

Daniel Bramhall


People also ask

How do you convert corner radius to TextField?

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.

How do I create a rounded border in Swift?

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.

How do you round the edges of a button in SwiftUI?

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.

How do I change the border color in Swift?

borderColor = (UIColor( red: 0.5, green: 0.5, blue:0, alpha: 1.0 )). CGColor; What I do in swift and what ALWAYS works: myTextField.


1 Answers

You can use:

nameOfTextField.layer.cornerRadius = 15.0 nameOfTextField.layer.borderWidth = 2.0 nameOfTextField.layer.borderColor = UIColor.red.cgColor 
like image 196
FredLoh Avatar answered Sep 20 '22 15:09

FredLoh