xcode 如何禁用和隐藏 UITextField
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7071386/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to disable and hide a UITextField
提问by Shawn
Hi I'm new in iPhone development, how do you disable a UITextField in iPhone development? If it matters, it is a View-Based Application, and the UITextField is named abc.
嗨,我是 iPhone 开发的新手,你如何在 iPhone 开发中禁用 UITextField?如果重要的话,它是一个基于视图的应用程序,并且 UITextField 被命名为 abc。
Thanks
谢谢
采纳答案by Matt S.
You use [abc setEnabled:NO]
to disallow the user to edit it, or setHidden
to completely hide it
你[abc setEnabled:NO]
用来禁止用户编辑它,或者setHidden
完全隐藏它
回答by progrmr
If you want to hide it completely:
如果你想完全隐藏它:
abc.hidden = YES;
If you just want to prevent user interaction:
如果您只想阻止用户交互:
abc.userInteractionEnabled = NO;
Since UITextField is a subclass of UIView (and UIControl), all the UIView (and UIControl) methods (such as those I used above) are available.
由于 UITextField 是 UIView(和 UIControl)的子类,所有 UIView(和 UIControl)方法(例如我上面使用的那些)都可用。
回答by Hyman Humphries
[textField setHidden:YES];
[textField setHidden:NO];
If it is hidden, the user can't interact with it or see it.
如果它是隐藏的,用户将无法与它交互或看到它。
回答by Louie
You can do this a few ways.
您可以通过几种方式做到这一点。
abc.alpha = 0; //text field is there, just transparent, so it can't be seen.
abc.hidden = TRUE; // textfield is hidden, not on View at all.
abc.userInteractionEnabled = FALSE; // user can see the text field and any text
// that has already been set but cannot edit