Changing UITextField borderstyle in didEndEditing

邮差的信 提交于 2020-01-03 09:19:06

问题


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?


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/12971454/changing-uitextfield-borderstyle-in-didendediting

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!