我有三个按钮可以更改背景的颜色。我想在按下时隐藏红色按钮。如果按下GREEN或BLUE按钮,则显示它。 GREEN和BLUE按钮也是如此。按下时隐藏UIButton,然后在另一个按钮被按下时显示它
我找不到方法叫removeFromSuperview
。在ObjectiveC中,我曾使用mybutton.hidden = true
但这不起作用。
ViewController: UIViewController {
@IBAction func RED(_ sender: Any) {
print("background was \(String(describing: self.view.backgroundColor))")
self.view.backgroundColor = UIColor.red
print("background is now \(String(describing: self.view.backgroundColor))")
}
@IBAction func GREEN(_ sender: Any) {
print("background was \(String(describing: self.view.backgroundColor))")
self.view.backgroundColor = UIColor.green
print("background is now \(String(describing: self.view.backgroundColor))")
}
@IBAction func BLUE(_ sender: UIButton) {
print("background was \(String(describing: self.view.backgroundColor))")
self.view.backgroundColor = UIColor.blue
print("background is now \(String(describing: self.view.backgroundColor))")
}
你应该可以做'button.isHidden = true'?如果它在ObjC中工作,它也应该在Swift中工作(通过翻译)。 – Peterdk
hmm。也许我做错了什么!我会再尝试。 – Splenso
nope我再次尝试,得到UIButton没有成员“ishidden” – Splenso