SemAllush
SemAllush

Reputation: 479

How do I remove the black border of a textfield?

I made a textfield in IB with the following settings:

The result is that the inside of the field is 15%, but there's a very thin visible border that isn't, and I want that removed. I've tried doing it in code like this:

textField.borderStyle = UITextBorderStyle.None
textField.layer.cornerRadius = 10
textField.layer.borderColor = UIColor(red:1.0,green:1.0,blue:1.0,alpha:0.15).CGColor

But this just puts the border on the inside covering the actual textfield.

Textfield:

enter image description here

Upvotes: 5

Views: 11205

Answers (5)

Al Walid Ashik
Al Walid Ashik

Reputation: 1779

I've tried several ways to remove the broder by programmatically and other suggested ways but later figured out this is the only way it removes the border from UITextField. Just select in interface builder, Border Style option

enter image description here

Upvotes: 2

Anil
Anil

Reputation: 272

Swift3

passwordTF.layer.borderColor = UIColor.clear.cgColor

For me its working as well as

mobileNumberTF.borderStyle = .none

Upvotes: 2

Mark Filter
Mark Filter

Reputation: 453

Swift 3 / Swift 4

The simplest approach to achieving a border-free textfield is to change the style of the textfield.

Steps

  1. Make a IBOutlet reference to the textfield.
  2. Set the textfield's border style to none.

Example Code

// Reference
@IBOutlet var tf: UITextField!

override func viewDidLoad() {
    super.viewDidLoad()

    // Email TextField: no border
    tf.borderStyle = .none
}

The Result

Image of how to remove boarder for textfield in Swift 3 Swift 4

Upvotes: 6

Birendra
Birendra

Reputation: 625

Try this one

self.nameTextField.borderStyle = UITextBorderStyleNone;

Upvotes: 0

LorenzOliveto
LorenzOliveto

Reputation: 7936

Try to add this:

textField.layer.borderWidth = 0

Additionally, from the screenshot, it seems that textField.layer.cornerRadius = 10 is ignored, make sure that your textField property is connected to the actual UITextField.

Upvotes: 2

Related Questions