Objective-c - iOS - 隐藏/取消隐藏标签、文本字段等

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5829969/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 19:44:22  来源:igfitidea点击:

Objective-c - iOS - hide/unhide label, textfield etc

objective-cioslabelhide

提问by Firejs

I want to hide/unhide controls of a subview in a view. For example: When a button action occurs, some labels will become hidden then unhide on a subsequent button action and so on. I have implemented this functionality through Interface Builder. How can I do the same implementation programmatically?

我想在视图中隐藏/取消隐藏子视图的控件。例如:当一个按钮动作发生时,一些标签将被隐藏,然后在随后的按钮动作中取消隐藏等等。我已经通过 Interface Builder 实现了这个功能。如何以编程方式执行相同的实现?

I've tried

我试过了

[label1 hidden: true];

which hasn't worked for me.

这对我不起作用。

回答by necixy

Here is the answer:

答案如下:

[label1 setHidden:YES];

YESis Objective-C's version of true.

YES是 Objective-C 的true.

回答by Aswathy Bose

To hide a label:

隐藏标签:

self.yourlabelname.hidden = YES;

回答by Sraavan reddy

Use [self.view addsubview:self.label];to make the label visible.

使用[self.view addsubview:self.label];以使标签可见。

Use [self.label removefromSuperview];to remove from Superview.

用于[self.label removefromSuperview];从超级视图中删除。