Pregunta

In my UIColor category I have this following method.

- (UIColor *)lighterColor
{
    CGFloat h, s, b, a;
    if ([self getHue:&h saturation:&s brightness:&b alpha:&a])
        return [UIColor colorWithHue:h
                          saturation:s
                          brightness:MIN(b * 1.3, 1.0)
                               alpha:a];
    return nil;
}

It works great with "Colors". But with Greys shades like [UIColor darkGrayColor] or [UIColor lightGrayColor] it returns a false.

Any idea why ?

And how I could fix my method to work with grey colors ?

¿Fue útil?

Solución

I didn't find the "why"

But here is the how : use getWhite:alpha

- (UIColor *)lighterColor
{
    CGFloat h, s, b, a;
    if ([self getHue:&h saturation:&s brightness:&b alpha:&a]) {
        return [UIColor colorWithHue:h
                          saturation:s
                          brightness:MIN(b * 1.3, 1.0)
                               alpha:a];
    }

    CGFloat white, alpha;
    if ([self getWhite:&white alpha:&alpha]) {
        white = MIN(1.3*white, 1.0);
        return [UIColor colorWithWhite:white alpha:alpha];
    }

    return nil;
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top