我有三個按鈕可以更改背景的顏色。我想在按下時隱藏紅色按鈕。如果按下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