This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// color - source color, which is must be replaced | |
// withColor - target color | |
// tolerance - value in range from 0 to 1 | |
func replaceColor(color: UIColor, withColor: UIColor, image: UIImage, tolerance: CGFloat) -> UIImage { | |
// This function expects to get source color(color which is supposed to be replaced) | |
// and target color in RGBA color space, hence we expect to get 4 color components: r, g, b, a | |
assert(color.cgColor.numberOfComponents == 4 && withColor.cgColor.numberOfComponents == 4, | |
"Must be RGBA colorspace") |