4

I want to remove the border of UITextField dynamically.

I tried [stringTextField setBorderStyle:UITextBorderStyleNone];

but nothing happened. Any idea?

Burak
  • 5,706
  • 20
  • 70
  • 110
  • Check this thread http://stackoverflow.com/questions/5789816/how-to-set-border-style-of-a-uitextfield – Ekram Nov 21 '13 at 09:09
  • Is there a chance you’re not on the main thread when you’re calling this? If it’s a network callback or other async method, you will need to `dispatch_async()` to the main queue. – Zev Eisenberg May 12 '14 at 17:23

3 Answers3

4

Is the TextField already displayed in the view when this happens? If so, you (probably) need to execute the following:

[stringTextField setBorderStyle:UITextBorderStyleNone];
[stringTextField setNeedsDisplay];

in order for the view to redraw the TextField, sans border. Note that there's no guarantee the system will immediately redraw the textField. You're indicating to the system that you'd like the field to be redrawn.

Sujay
  • 2,510
  • 2
  • 27
  • 47
Matt S.
  • 1,882
  • 13
  • 17
  • I did what you said. If I do UITextBorderStyleRoundedRect, it is ok. But if I write UITextBorderStyleNone, nothing happens – Burak Jul 03 '12 at 21:44
  • Actually for UITextBorderStyleRoundedRect, no need to setNeedsDisplay. – Burak Jul 03 '12 at 21:48
4

With an existing UITextField I found that this worked:

[textField setEnabled:NO];
[textField setBorderStyle:UITextBorderStyleNone];

while this did not (the border remained in the view):

[textField setBorderStyle:UITextBorderStyleNone];
[textField setEnabled:NO];
T.J.
  • 3,942
  • 2
  • 32
  • 40
2

Try this ones.

textField.borderStyle = UITextBorderStyleRoundedRect;
textField.borderStyle = UITextBorderStyleNone;
kleopatra
  • 51,061
  • 28
  • 99
  • 211
Venky145
  • 31
  • 7