How to compare a color in swift
Try CGColorEqualToColor(_ color1: CGColor!, _ color2: CGColor!) -> Bool
.
I've come up with this in a playground, I've assigned the backgroundColor property of the UICollectionViewCell with a UIColor and then created a UIColor from it's layer.backgroundColor CGColor property:
let blue = UIColor.blueColor()
let collectionCell = UICollectionViewCell()
collectionCell.backgroundColor = blue
let cellLayerBgrndColor = UIColor(CGColor: collectionCell.layer.backgroundColor!)
if blue == cellLayerBgrndColor {
print("equal") // Prints equal
}
extension CGColor: Equatable { }
public func ==(lhs: CGColor, rhs: CGColor) -> Bool {
return CGColorEqualToColor(lhs,rhs)
}
let color1 = UIColor(hue: 0, saturation: 1, brightness: 1, alpha: 1).CGColor
let color2 = UIColor.redColor().CGColor
print(color1 == color2) // "true\n"