calvinklein calvinklein - 10 months ago 24
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)


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.