作者:机智的树獭 | 来源:互联网 | 2023-05-17 00:47
Iamusingthefollowingfunctiontochangethesaturation,brightnessandalphaofaUIColor:我正在
I am using the following function to "change" the saturation, brightness and alpha of a UIColor
:
我正在使用以下函数来“改变”UIColor的饱和度、亮度和alpha:
//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.
在ios11 (GM)之前,运行得非常好。然而,现在[UIColor getHue::bright:alpha:]返回NO, hsba值不会改变。
Comment in UIColor.h
says:
在用户界面颜色发表评论。h说:
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.
如果接收器是兼容的颜色空间,则会填充任何非空参数,并返回“YES”。否则,参数将保持不变并返回'NO'。
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.
“兼容颜色空间”在这里是什么意思?我需要转换颜色空间吗?我怎么做到的?我的.xcassets中的所有颜色都在sRGB中。
EDIT: Kind of a fix is to use the following way to get the HSBA values:
编辑:一种修复方法是使用以下方法获取HSBA值:
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];
1 个解决方案