calvinklein calvinklein - 1 year ago 58
Swift Question

How to make if loop which compares color?

I would like to ask how can I make an if-statement which compares color? Mine doesn't work...

animations: {
self.labelTen.layer.backgroundColor = self.timeOneColor.CGColor

if(self.labelTen.backgroundColor == timeOneColor)

Answer Source

If you want to specifically compare colors you can check it by following method

if (CGColorEqualToColor(self.labelTen.backgroundColor.CGColor, timeOneColor.CGColor))
    //Two colors are same

Return true if color1 is equal to color2; false otherwise.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download