首页 > 代码库 > iOS 获取UIColor对象的HSB字符串值。
iOS 获取UIColor对象的HSB字符串值。
/**
* 获取UIColor对象的HSB字符串值。
*
*/
- (NSString *)getHSBStringByColor:(UIColor *)originColor {
// Method provided by the Colours class extension
NSDictionary *hsbDict = [selfgetHSBAValueByColor:originColor];
return [NSStringstringWithFormat:@"(%0.2f, %0.2f, %0.2f)",
[hsbDict[@"H"]floatValue],
[hsbDict[@"S"]floatValue],
[hsbDict[@"B"]floatValue]];
}
/**
* 获取UIColor对象的HSBA值。
*
*/
- (NSDictionary *)getHSBAValueByColor:(UIColor *)originColor
{
CGFloat h=0,s=0,b=0,a=0;
if ([originColor respondsToSelector:@selector(getHue:saturation:brightness:alpha:)]) {
[originColorgetHue:&h saturation:&sbrightness:&b alpha:&a];
}
return @{@"H":@(h),
@"S":@(s),
@"B":@(b),
@"A":@(a)};
}
iOS 获取UIColor对象的HSB字符串值。