alexdrone / ios-fontawesome

NSString+FontAwesome
1.74k stars 254 forks source link

Build warning in +imageWithIcon:backgroundColor:iconColor:andSize: #44

Open BlakeLucchesi opened 9 years ago

BlakeLucchesi commented 9 years ago

I found a build error while doing an "Analyze" build in my project. The fontSize variable gets assigned a value but is never used inside the method. I'm assuming this was supposed to get set as one of the attributes in the call to -drawInRect:withAttributes but I am not sure so I didn't create a PR with any changes.

+(UIImage*)imageWithIcon:(NSString*)identifier backgroundColor:(UIColor*)bgColor iconColor:(UIColor*)iconColor andSize:(CGSize)size{
    if (!bgColor) {
        bgColor = [UIColor clearColor];
    }
    if (!iconColor) {
        iconColor = [UIColor whiteColor];
    }

    UIGraphicsBeginImageContextWithOptions(size, NO, 0.0f);

    //// Abstracted Attributes
    NSString* textContent = [NSString fontAwesomeIconStringForIconIdentifier:identifier];

    CGRect textRect = CGRectZero;
    textRect.size = size;

    //// Retangle Drawing
    UIBezierPath *path = [UIBezierPath bezierPathWithRect:textRect];
    [bgColor setFill];
    [path fill];

    //// Text Drawing
    int fontSize = size.width;
    UIFont *font = [UIFont fontWithName:kFontAwesomeFamilyName size:fontSize];
    @autoreleasepool {
        UILabel *label = [UILabel new];
        label.font = font;
        label.text = textContent;
        fontSize = fa_constraintLabelToSize(label, size, 500, 5);
        font = label.font;
    }
    [iconColor setFill];

    [textContent drawInRect:textRect withAttributes:@{NSFontAttributeName : font,
                                                      NSForegroundColorAttributeName : iconColor,
                                                      NSBackgroundColorAttributeName : bgColor
                                                      }];

    //Image returns
    UIImage * image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return image;
}

screenshot 2015-05-06 11 11 55

hexxellor commented 9 years ago

I get that too... and this text drawing code looks strange to me... I don't see the point in getting the fontSize return value at that point, especially if it's going to go unused.

    //// Text Drawing
    int fontSize = size.width;
    UIFont *font = [UIFont fontWithName:kFontAwesomeFamilyName size:fontSize];
    @autoreleasepool {
        UILabel *label = [UILabel new];
        label.font = font;
        label.text = textContent;
        fontSize = fa_constraintLabelToSize(label, size, 500, 5);
        font = label.font;
    }