Code Monkey home page Code Monkey logo

ios-fontawesome's Introduction

FontAwesome+iOS

Font awesome is an iconic font. Read more about it on http://fortawesome.github.com/Font-Awesome/

This category brings this great iconic font on iOS.

Usage

First, make sure you have FontAwesome.ttf bundled in your project and that UIAppFonts key in the project's plist file contains a String item named FontAwesome.ttf Then add the NSString+FontAwesome category to the project.

UILabel *label = [...]
label.font = [UIFont fontWithName:kFontAwesomeFamilyName size:20];

You can now use enums for all the different iconic characters

label.text = [NSString fontAwesomeIconStringForEnum:FAGithub];

or you can reference them by using the class identifiers listed here http://fortawesome.github.io/Font-Awesome/icons

label.text = [NSString fontAwesomeIconStringForIconIdentifier:@"fa-github"];

or you can add the UIImage+FontAwesome category to generate icon image directly

UIImage *github = [UIImage imageWithIcon:@"fa-github" backgroundColor:[UIColor purpleColor] iconColor:[UIColor colorWithRed:0.9 green:0.9 blue:0.9 alpha:255] iconScale:2.f fontSize:20];

then you will get an icon like this

image

That's all.
Have a look at the small demo project for further information.

FAImageView

FAImageView is now extended and contains a new property called defaultView that is shown when the image is set to nil. It is possible to use one the font-awesome icon as a default placeholder for an image view.

FAImageView *imageView = [[FAImageView alloc] initWithFrame:CGRectMake(0.f, 0.f, 100.f, 100.f)];
imageView.image = nil;
[imageView setDefaultIconIdentifier:@"fa-github"];

Troubleshooting

Some icons are not available on some devices

Keep in mind that if you have installed the FontAwesome font in your iOS system (with InstaFont for example), the embedded font in your App will not be used! So if your system FontAwesome font is v4.2, you will never be able to display icons from v4.3 and v4.4 for example from the embedded font.

Two solutions :

  1. Remove the font profile from your iOS device
  2. Rename the Postscript name of file FontAwesome.ttf with a tool like ttx for example and use the new name in NSString+FontAwesome.h

Here is the step by step for second solution :

  • Install fonttools

    git clone https://github.com/behdad/fonttools.git ;
    cd fonttools/
    sudo python setup.py install
    
  • Convert the FontAwesome.ttf file to ttx format

    cd your_app/Pods/FontAwesome+iOS/Resources/
    ttx FontAwesome.ttf
    
  • Replace all occurence of FontAwesome with FontAwesome440 for example in ttx file and save

  • Convert back ttx font to ttf

    ttx FontAwesome.ttx
    mv FontAwesome.ttf FontAwesome.ttf.orig
    mv FontAwesome#1.ttf FontAwesome.ttf
    
  • In file NSString+FontAwesome.h, change font Postscript name :

    static NSString *const kFontAwesomeFamilyName = @"FontAwesome440";
    
  • Build, run and dance

License

This project uses the FontAwesome fix made by Pit Garbe that you can find at https://github.com/leberwurstsaft/FontAwesome-for-iOS Version 2.0 of the Font Awesome font, CSS, and LESS files are licensed under CC BY 3.0: http://creativecommons.org/licenses/by/3.0/ A mention of 'Font Awesome - http://fortawesome.github.com/Font-Awesome' in human-readable source code is considered acceptable attribution (most common on the web). If human readable source code is not available to the end user, a mention in an 'About' or 'Credits' screen is considered acceptable (most common in desktop or mobile software)

ios-fontawesome's People

Contributors

a2 avatar alexdrone avatar arjunsharma avatar elfsundae avatar hysteria avatar jasontrask avatar jeremyanticouni avatar joshfuggle avatar mattleff avatar metabren avatar potsky avatar rsattar avatar runmad avatar tapthaker avatar vphamdev avatar xjrcode avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ios-fontawesome's Issues

FA 4.2 icons not showing

I have upgraded to FA 4.2 but icons for paypal and others are not showing up though their enums are there in the lib.

add font to ios project

Hello, I am new IOS developer, and I dont know how exactly I have to edit the plist file to add the font, thank you.

Missing Icons

Missing icon-moon (unicode F186) and icon-bug (unicode F188)

Edit: Looks like these were from the 3.2 update, didn't see that.

CocoaPods

I am running a fork here: https://github.com/paramaggarwal/FontAwesome-iOS that is using the name FontAwesome on CocoaPods.

The code is exactly this repo itself. I would like that repo to be merged into this one and I would like to hand over ownership of the CocoaPod to you. Please get in touch with me using the email on my Github Profile.

Excellent work with the repo, @alexdrone!

Icon not showing and app crash on second access

Hi,

I have just included the NSString+FontAwesome.h and .m on my project along with FontAwesome.ttf.
I made the changes on info.plist and also verified that Build Phase is correct copying the resources. I also checked the output folder and expected files are there.

So now the problem is the icon is not shown when I first access. just a box with an ? appear then when try to access a second time app chrash on the following method:

  • (NSString*)fontAwesomeIconStringForEnum:(FAIcon)value {
    return [NSString fontAwesomeUnicodeStrings][value];
    }

with error: EXC_BAD_ACCESS

Thanks in advance,

-Martin

Battery 0..4 are rendered truncated

Hi there,
this package is awesome (yes!) and saving us a lot of time, but I am running is something that is either an issue or something I cannot understand.

When doing
let batteryIcon = UIImage.fontAwesomeIconWithName(.Battery0, textColor: UIColor.whiteColor(), size: CGSizeMake(12, 12))
I do get a 12 x 12 image but the battery image fills the space vertically and hence the right part is truncated (as the shape has a larger width).
I tries with ArrowsH that is has a larger width as well and it scales correctly (the icon does not fill the height)

Any idea where it might come from ?

Many thanks in advance.

numbers are a different colour?

this is odd, setting the title in a navbar to "F0n7" results in the numbers being grey and the letters white.

I'm using UINavigationBar appearance to set the title text attributes.

Anyone else getting this?

Is icon-spin supported?

I'd like to use icon-spinner as an activity indicator. In css I would do this by assigning the icon-spin class. Is this functionality supported in FontAwesome+IOS?

WhatsApp Icon

WhatsApp icon is missing. :(

Fontawesome contains fa-whatsapp but its missing in this lib.

Cocoapods

Hi,

Thanks for this really useful lib, I was about to make mine when I found yours.
I'd love to use it with Cocoapods, even if I can do it "myself" in my podfile, it'll be great for the community if you could release this on CocoaPods.

If you need help writing the pod spec (https://github.com/CocoaPods/CocoaPods/wiki/The-podspec-format) and submitting it to Cocoapods, I'll be glad to help.

Thanks!!!

Failed to download 'FontAwesome+iOS'

==> pod update
Update all pods

Analyzing dependencies
Pre-downloading: FontAwesome+iOS from [email protected]:alexdrone/ios-fontawesome.git

[!] Error installing FontAwesome+iOS
[!] Failed to download 'FontAwesome+iOS'.

Same error with pod install

==> pod install
Analyzing dependencies
Pre-downloading: FontAwesome+iOS from [email protected]:alexdrone/ios-fontawesome.git

[!] Error installing FontAwesome+iOS
[!] Failed to download 'FontAwesome+iOS'.

Only works with enum but not with string id

if I use FAIconxxx it works, but if I try string id "fa-xxx" or simply "xxx" it always shows the default image.

I included all the header files already. Anything missing?

Is there any way to put font from storyboard?

A lot of times we have designer updating the asset and it would very nice if we can specified through the UI. However I only see the way to input is through the code. Let me know if anyone knows how to enter through ui.

Shinya

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

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?

Icons show up in simulator but not phone

I just upgraded to the 4.x line, and have two icons that show up fine in the simulator, but not on a device: "fa-thumbs-up" and "fa-stack-overflow". Other icons seem to work fine.

Some characters are not aligned center.

Please check the screenshot. I add fonts in tableview cells and the UILabels' frame are the same. Is it a font issue?
Screen Shot 2013-01-25 at 2 30 40 AM

BTW, I'm interested how can you reference the character for font-awesome with integer value? I know little about fonts things. Would you please give me some hint or keyword to research?

Icon + Text

Is there any way to add an icon + any text to a label or image?

e.g:

label.text = [NSString fontAwesomeIconStringForIconIdentifier:@"fa-github + myText"];

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

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.