Giter VIP home page Giter VIP logo

iosicomoon's Introduction

IOS Ico Moon

Use an ICOMoon generated icon font in your IOS app!

Font-awesome and other icon fonts are just awesome. ICOMoon (a web app that lets you hand pick glyphs from multiple icon fonts and generate a custom font file that contains only the selected glyphs) is beyond awesome!

Here is how I use that stuff in my apps:

1. Generate a custom icon font using the icomoon app

  • Go here: http://icomoon.io/app/
  • Select icons from various font
  • Click the Font button at the bottom to generate the font
  • click download

For instance the sample font in the repo was generated by picking 5 icons from 5 different fonts, and it is only 3KB (font-awesome alone is 65KB):

icons

2. Generate code

  • Extract the zip and go to the fonts sub-folder.
  • Run the generateHeader.py python script provided in the repo...

This script will parse the icomoon.dev.svg file and create a new file named IcomoonIcons.h. This is hard-codedin the python script. The generated files contains a bunch of #defines in it, one UTF code per glyph.

For instance, the previous icon set will generate these 5 #defines:

#define  ICOMOON_BUBBLES "\uE000"
#define  ICOMOON_TARGET "\uE001"
#define  ICOMOON_SNOWY "\uE002"
#define  ICOMOON_MUSIC "\uF001"
#define  ICOMOON_CHART "\uE003"

3. Use it in your app

  • Add the IcomoonIcons.h file and the ttf font file icomoon.ttf in your app project.
  • Make sure your add an entry in your app info.plist for the icomoon.ttf font file ("Fonts provided by application"/UIAppFonts row).
  • Optionaly, add the IcoMoon.m and IcoMoon.h to your project. This class is a very simple class that imports the generated IcomoonIcons.h and that contains only one helper method:
+(NSString *)iconString:(char *)icon
{
    NSString *string = [NSString stringWithUTF8String:icon];
    return string;
}

you could go by without it really, I just find

[NSString stringWithUTF8String:ICOMOON_BUBBLES];

not as readable as

[IcoMoon iconString:ICOMOON_BUBBLES];

In your app, you can now simply make a UILabel look like an icon:

[self.label setFont:[UIFont fontWithName:@"icomoon" size:64.0f]];
self.label.text = [IcoMoon iconString:ICOMOON_BUBBLES];

The key thing is to set the font to @"icomoon"... Alternatively if you are using NUI as I am:

Label:BigIcon {
    font-name: icomoon;
    font-size: 64;
    text-align: center;
}

app

Run the ExampleApp iPhone app to see it in action.

I guess you could make the generation of the IcomoonIcons.h file a custom build phase so everything is updated after you update the font... Feel free to send me a pull request!

iosicomoon's People

Contributors

sebastienwindal avatar horseshoe7 avatar

Watchers

 avatar James Cloos avatar

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.