按下按钮时更改按钮“+”、“-”、“/”、“*”的背景(清晰等号)。 (IOS)
Change the background of the buttons "+", "-", "/", "*" when the button is pressed (clear and equal). (IOS)
怎样才能让按下按钮时(清晰等号)背景“+”、“-”、“/”、“*”变成灰色,和按下前一样。
@IBAction func AnAnimate(_ sender: UIButton) {
if sender.currentBackgroundImage == #imageLiteral(resourceName: "image_off") {
sender.setBackgroundImage(#imageLiteral(resourceName: "Image_on"), for: .normal)
} else {
sender.setBackgroundImage(#imageLiteral(resourceName: "image_off"), for: .normal)
}
if (previousButton !== sender) {
previousButton.setBackgroundImage(#imageLiteral(resourceName: "image_off"), for: .normal)
previousButton = sender
}
}
假设您有 outlet
或 button
,那么当按下 button
时,然后像这样更改所有 button
的 background
颜色。
button1.backgroundColor = UIColor.gray
button2.backgroundColor = UIColor.gray
怎样才能让按下按钮时(清晰等号)背景“+”、“-”、“/”、“*”变成灰色,和按下前一样。
@IBAction func AnAnimate(_ sender: UIButton) {
if sender.currentBackgroundImage == #imageLiteral(resourceName: "image_off") {
sender.setBackgroundImage(#imageLiteral(resourceName: "Image_on"), for: .normal)
} else {
sender.setBackgroundImage(#imageLiteral(resourceName: "image_off"), for: .normal)
}
if (previousButton !== sender) {
previousButton.setBackgroundImage(#imageLiteral(resourceName: "image_off"), for: .normal)
previousButton = sender
}
}
假设您有 outlet
或 button
,那么当按下 button
时,然后像这样更改所有 button
的 background
颜色。
button1.backgroundColor = UIColor.gray
button2.backgroundColor = UIColor.gray