Return lighter color from SKColor using HSL lightness factor

后端 未结 2 1104
轻奢々
轻奢々 2020-12-07 05:36

I have an iOS SKColor, that I want to convert to a lighter shade (that is opaque with no opacity/no transparency), therefore I would like to implement a function using the H

2条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-07 06:16

    As the official SKColor doc says, on iOS, a SKColor is just a UIColor. Hence:

    UIColor *uicolor = (UIColor *)skcolor;
    CGFloat h, s, b, a; // lightness is called 'brightness' 
    [uicolor getHue:&h saturation:&s brightness:&b alpha:&a];
    
    // (play with your brightness value here)
    
    SKColor *skcolor2 = (SKColor *)[UIColor colorWithHue:h saturation:s brightness:b alpha:a];
    

提交回复
热议问题