alexdrone / ios-fontawesome

NSString+FontAwesome
1.74k stars 254 forks source link

How to add the font awesome image to a tab bar item image? #25

Open jas54 opened 10 years ago

jas54 commented 10 years ago

From the documentation, there are two options to use font awesome image[ via label strings and FAImageView]. But how to use the font awesome image to a UIImage? For tab bar items with title, how can i set the font awesome image as the tab bar item image?

artisani commented 10 years ago

@jas54: I've also tried to use fontawesome to acheive this in my iOS app and I haven't managed yet. Did you solve it eventually?

jimmychu0807 commented 10 years ago

Try this project: http://nschum.github.io/FontAwesomeIconFactory/

For specific on how to create a tabbar image, refer to this file:

https://github.com/nschum/FontAwesomeIconFactory/blob/master/FontAwesomeIconFactoryDemo/FontAwesomeIconFactoryDemo/TabBarController.m

cloud-hot commented 9 years ago

I have saw a API "(UIImage)imageWithIcon:(NSString)identifier backgroundColor:(UIColor)bgColor iconColor:(UIColor)iconColor iconScale:(CGFloat)scale andSize:(CGSize)size;" in the UIImage+FontAwesome.h But if i use it through swift it will also post a compiler error

UIImage(icon: <String!>, backgroundColor: <UIColor!>, iconColor: <UIColor!>, iconScale: , andSize: )

Could you tell me how to use this API? Thanks!

mzamoras commented 9 years ago

I tried this and seemed to work just fine! But only tried for TabBarItems. It's either a fix or just a work around. I`m using Xcode 6.3 and get it working on real device, besides simulator.

Take a look.

UIImage *iconDefault  = [UIImage imageWithIcon:@"fa-github" backgroundColor:[UIColor clearColor] iconColor:[UIColor whiteColor] andSize:CGSizeMake(32, 32)];
UIImage *iconSelected = [UIImage imageWithIcon:@"fa-github" backgroundColor:[UIColor clearColor] iconColor:[UIColor blueColor] andSize:CGSizeMake(32, 32)];

UITabBarItem *tabItem = [_tabBar.items objectAtIndex:0];
tabItem.image         = [iconDefault imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
tabItem.selectedImage = [iconSelected imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];];
aqua30 commented 9 years ago

You can check this https://github.com/aqua30/FontAwesomeTab . It lets you add font awesome images in the tabs icon. May be its helpful to you.