Skip to content

Conversation

@ViacheslavSoroka
Copy link

Code below:

if(rgba[3] == 0) {
    CGFloat alpha = ((CGFloat)rgba[3])/255.0;
    CGFloat multiplier = alpha/255.0;
    return [UIColor colorWithRed:((CGFloat)rgba[0])*multiplier 
                                          green:((CGFloat)rgba[1])*multiplier
                                            blue:((CGFloat)rgba[2])*multiplier
                                          alpha:alpha];
}

could be rewritten as:

if(rgba[3] == 0) {
    CGFloat alpha = 0/255.0;
    CGFloat multiplier = 0/255.0;
    return [UIColor colorWithRed:((CGFloat)rgba[0])*0
                                          green:((CGFloat)rgba[1])*0
                                            blue:((CGFloat)rgba[2])*0
                                          alpha:alpha];
}

or:

if(rgba[3] == 0) {
    return [UIColor clearColor];
}

Also, there is no need to do type casting to CGFloat. Type will be inferred automatically because of divisor 255.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant