Cannot remove border of UITextField dynamically

岁酱吖の 提交于 2019-12-06 04:28:58

问题


I want to remove the border of UITextField dynamically.

I tried [stringTextField setBorderStyle:UITextBorderStyleNone];

but nothing happened. Any idea?


回答1:


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.




回答2:


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];



回答3:


Try this ones.

textField.borderStyle = UITextBorderStyleRoundedRect;
textField.borderStyle = UITextBorderStyleNone;


来源:https://stackoverflow.com/questions/11319377/cannot-remove-border-of-uitextfield-dynamically

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