Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing UITextField borderstyle in didEndEditing

I want to highlight a uitextfield when a user is editing it, so I set my textfield's borderstyle default to UITextBorderStyleNone and use the uitextfields delegates as following:

- (void)textFieldDidBeginEditing:(UITextField *)textField
{
    [textField setBorderStyle:UITextBorderStyleBezel];
}

- (void)textFieldDidEndEditing:(UITextField *)textField
{
    [textField setBorderStyle:UITextBorderStyleNone];
}

The Bezel style gets set and rendered, but when the endediting is called, the none style is not applied. I tried changing the none to another (say rounded rect), but that one does render properly.

Does anybody know how I can get this to work?

like image 853
Myth1c Avatar asked Oct 19 '12 09:10

Myth1c


2 Answers

Yes, it is a bug. Anyway, I've solved by using this code:

textField.borderStyle = UITextBorderStyleLine;
textField.borderStyle = UITextBorderStyleNone;

This isn't a very beautiful method, but it does the work until Apple fixes this issue.

like image 65
Infinite Possibilities Avatar answered Nov 18 '22 22:11

Infinite Possibilities


I had this issue also. From my testing it looked as if I could set it to any style other than UITextBorderStyleNone.

A workaround that worked for me at least was disabling and re-enabling the textfield as seen below:

- (void)textFieldDidEndEditing:(UITextField *)textField {
    textField.enabled = NO;
    textField.borderStyle = UITextBorderStyleNone;
    textField.enabled = YES;
}

I don't really like it but it works for now.

like image 2
Hodson Avatar answered Nov 18 '22 23:11

Hodson