Skip to content

Instantly share code, notes, and snippets.

@DiogoAndre
Last active May 12, 2018 21:50
Show Gist options
  • Save DiogoAndre/8f5cc66024217d34c465 to your computer and use it in GitHub Desktop.
Save DiogoAndre/8f5cc66024217d34c465 to your computer and use it in GitHub Desktop.
Use font icon to create a NSMutableAttributedString in RubyMotion

Get the font files from http://octicons.github.com and copy the octicons-local.ttf file to the /resources directory at the root of your project.

my_icon = NSMutableAttributedString.alloc.initWithString("\uf00e")
my_icon.addAttribute(NSFontAttributeName, value: NSFont.fontWithName("github-octicons",size:30), range: NSMakeRange(0, 1))

The string in initWithString will be the unicode value of the char that represents the icon you want. You can check the unicode value for the icons in the CSS file that comes when you download the font.You can also get the unicode value when you select an icon on octicons.github.com.

I've tested on a Mac app, but it should work the same on a iOS app

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment