How to compare colors in swift

后端 未结 4 1734
既然无缘
既然无缘 2020-12-19 08:39

I want change button background for different state. I try so:

 @IBAction func addToShedulerAction(sender: UIButton) {   
       println(sender.backgroundCol         


        
4条回答
  •  执笔经年
    2020-12-19 09:27

    Remember when you are comparing UIColors you have to write description at the end of the color for both side, if you don't write this, every time it will enter into else block. For Example, see the below code

    if(ocularPlus1Btn.backgroundColor?.description == UIColor.init(red: 23.0 / 255.0, green: 82 / 255.0, blue: 84 / 255.0, alpha: 1).description) {
       return "positive"
    } else {
       return "negative"
    }
    

提交回复
热议问题