Xcode 快速删除按钮
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/33918942/
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-09-15 08:15:16 来源:igfitidea点击:
Xcode swift remove button
提问by Mat Koffman
I add a button like this:
我添加一个这样的按钮:
var button: UIButton!
button = UIButton(type: UIButtonType.System) as UIButton
button.frame = CGRectMake(screenWidth/2-50, 40, 100, 50)
button.addTarget(self, action: "buttonAction:", forControlEvents: UIControlEvents.TouchUpInside)
self.view.addSubview(button)
And then I want to remove it with this code:
然后我想用这个代码删除它:
self.button.removeFromSuperview()
But it doesn't disappear. Why doesn't it disappears?
但它不会消失。为什么不消失?
回答by drdrdrdr
If you connect the button to your code by creating an IBOutlet, you can remove it from the view with:
如果通过创建 IBOutlet 将按钮连接到代码,则可以使用以下命令将其从视图中删除:
button.hidden = true