开发者

UITextField problems in iOS 5 by changing UITextFieldBorderStyle at runtime

开发者 https://www.devze.com 2023-04-13 09:19 出处:网络
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'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 = UITextBorderStyleRound开发者_运维知识库edRect;

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..


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


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.


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消