PrideChung / FontAwesomeKit

Icon font library for iOS. Currently supports Font-Awesome, Foundation icons, Zocial, and ionicons.
MIT License
2.81k stars 308 forks source link

I could't set the colour of the icon #78

Closed burakkilic closed 8 years ago

burakkilic commented 8 years ago

Hello;

I want to set foreground of the icon like this:

    FAKFontAwesome *infoIcon = [FAKFontAwesome infoIconWithSize:70];
UIColor* color = [Helper color:@"#ff0043" withAlpha:1.0];
[infoIcon addAttribute:NSForegroundColorAttributeName value:color];
UIImage *iconImage = [infoIcon imageWithSize:CGSizeMake(90, 90)];
[self.infoButton setImage:iconImage forState:UIControlStateNormal];

My helper function takes hex code of the color and returns a UIColor.

+ (UIColor*)color:(NSString*)colorCode withAlpha:(float)alpha{
if(!colorCode)
    return [UIColor blackColor];
unsigned result = 0;
NSScanner *scanner = [NSScanner scannerWithString:colorCode];
[scanner setScanLocation:1]; // bypass '#' character
[scanner scanHexInt:&result];
return [UIColor colorWithHex:result alpha:alpha];
}

But icon is always black. Where am I wrong?

PrideChung commented 8 years ago

Try to pinpoint your problem first. Assign [UIColor redColor] to the icon and see if it turn red. If it do turn red, then the problem is in your helper function.

burakkilic commented 8 years ago

I am very sorry, I did a stupid mistake. Now all are ok. Thank you.