两个按钮的背景颜色都改变了
Posted
技术标签:
【中文标题】两个按钮的背景颜色都改变了【英文标题】:Both button background color changed 【发布时间】:2018-03-21 09:45:15 【问题描述】:当我使用该功能时,按钮无法正常工作。当我点击按钮时,按钮背景颜色会改变,当我们点击另一个按钮时,两个按钮的背景颜色都会改变。请告诉我如何解决这个错误。
@IBAction func btnNew(_ sender: Any)
if otlNewVisitor.isSelected == false
otlNewVisitor.isSelected == true
Button.buttonPressed(button: otlNewVisitor, boolResult: true, titleColor: UIColor.white, strImage: "icn-new-visitor-wht", bgColor: UIColor(red: 30/255, green: 104/255, blue: 140/255, alpha: 1), imgVW: imgNewVis)
//Entered SubmitDetails Screen
let submitVC = self.storyboard?.instantiateViewController(withIdentifier: "SubmitDetailsVC") as! SubmitDetailsVC
self.navigationController?.pushViewController(submitVC, animated: true)
else
otlNewVisitor.isSelected == false
//Button Colow did change
Button.buttonPressed(button: otlNewVisitor, boolResult: false, titleColor: UIColor(red: 30/255, green: 104/255, blue: 140/255, alpha: 1), strImage: "icn-new-visitor", bgColor: UIColor.white, imgVW: imgNewVis)
【问题讨论】:
显示Button.buttonPressed
的代码
另外,您没有在比较后使用==
设置状态(可能您收到警告)
【参考方案1】:
您可以将您的代码更改为我的代码。仅当您在 if-else 条件中设置 button 的选定值时才会发生这种情况。因此,您想删除该代码。效果很好。
@IBAction func btnNew(_ sender: Any)
if otlNewVisitor.isSelected == false
Button.buttonPressed(button: otlNewVisitor, boolResult: true, titleColor: UIColor.white, strImage: "icn-new-visitor-wht", bgColor: UIColor(red: 30/255, green: 104/255, blue: 140/255, alpha: 1), imgVW: imgNewVis)
//Entered SubmitDetails Screen
let submitVC = self.storyboard?.instantiateViewController(withIdentifier: "SubmitDetailsVC") as! SubmitDetailsVC
self.navigationController?.pushViewController(submitVC, animated: true)
else
//Button Colow did change
Button.buttonPressed(button: otlNewVisitor, boolResult: false, titleColor: UIColor(red: 30/255, green: 104/255, blue: 140/255, alpha: 1), strImage: "icn-new-visitor", bgColor: UIColor.white, imgVW: imgNewVis)
【讨论】:
以上是关于两个按钮的背景颜色都改变了的主要内容,如果未能解决你的问题,请参考以下文章