UITextField problems in iOS 5 by changing UITextFieldBorderStyle at runtime

只愿长相守 提交于 2019-12-10 19:27:48

问题


I'm suddenly having trouble with some UITextFields now that I'm testing on iOS 5 devices, even though I built the app in iOS 5 SDK and already let the bug slip through to release.

I have a textfield that allows input, and when you press a "lock" button, it calls:

textField.enabled = NO;
textField.borderStyle = UITextBorderStyleNone;

The Field "hides" but still acts like a label - important function for the app.

Then you press the "lock" button again and it calls:

textField.enabled = YES;
textField.borderStyle = UITextBorderStyleRoundedRect;

This works perfectly in 4.2/4.3 but in iOS 5 the only thing that appears is the beveled outline of the textfield with no white background color.

Setting .backgroundColor fixes it on iOS 5 but makes an ugly white square on 4.2/4.3.

I didn't see anything about these changes in the API diffs document, what am I missing here?? Thanks in advance..


回答1:


If you are fine with the white background, I fixed this commenting out the line that specifies a background color and setting the opaque property to NO

//[myTextField setBackgroundColor:[UIColor whiteColor]];

[myTextField setOpaque:NO];

This has resolved the issue for both iOS 4.3, and iOS 5.0

-Alex




回答2:


userInteractionEnabled is a property of the much more general UIView class, and as such may not behave as you expected with subclasses of UIControl, such as UITextField. Instead, you should set the enabled property to NO to temporarily disable a control, which in the case of UITextField would do precisely what you want.




回答3:


A possible fix is to set alpha to 0.00001. That gives you effectively hidden labels which can still respond to control events.




回答4:


I am having a similar problem, and the UITextBorderStyleNone was working fine in iOS 4.3, but on iOS 5 is stopped working. I think this is a bug from Apple, because it doesn't work on both the device and the simulator. I think your best shot here is to switch between the label and the text field as needed like darvids0n suggests till Apple solves the bug.



来源:https://stackoverflow.com/questions/7759729/uitextfield-problems-in-ios-5-by-changing-uitextfieldborderstyle-at-runtime

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