I am using the following function to "change" the saturation, brightness and alpha of a UIColor:
//UIColor *color = [self color:[UIColor redColor] saturation:0.5 brightness:0.5 alpha:0.5];
- (UIColor *)color:(UIColor *)color saturation:(CGFloat)saturation brightness:(CGFloat)brightness alpha:(CGFloat)alpha {
CGFloat h, s, b, a;
[color getHue:&h saturation:&s brightness:&b alpha:&a];
return [UIColor colorWithHue:h saturation:(s * saturation) brightness:(b * brightness) alpha:(a * alpha)];
}
Prior to iOS 11 (GM) this was working perfectly fine. However, now [UIColor getHue:saturation:brightness:alpha:] returns NO and the hsba values aren't getting changed.
Comment in UIColor.h says:
If the receiver is of a compatible color space, any non-NULL parameters are populated and 'YES' is returned. Otherwise, the parameters are left unchanged and 'NO' is returned.
What does "compatible color space" mean here? Do I have to convert color spaces? How do I accomplish that? All the colors in my .xcassets are in sRGB.
EDIT: Kind of a fix is to use the following way to get the HSBA values:
CGFloat rTemp, gTemp, bTemp, aTemp;
[color getRed:&rTemp green:&gTemp blue:&bTemp alpha:&aTemp];
CGFloat h, s, b, a;
[[UIColor colorWithRed:rTemp green:gTemp blue:bTemp alpha:aTemp] getHue:&h saturation:&s brightness:&b alpha:&a];