Take the 2-minute tour ×

Having an issue trying to use an icon font for scalable icons in a RubyMotion (ios) app.

I created a small set of icons from icomoon, and set the characters to 'A', 'B', and 'C'.

enter image description here

I imported this into the Font Book and it appears to respect the 'A', 'B', and 'C' characters:

enter image description here

To test, I fired up a word document and typed 'A', 'B', and 'C' and it appears to display fine:

enter image description here

Now, onto the RubyMotion app - I included the font in /resources:

enter image description here

(Loading Lobster and Open Sans from sub-directories work)

Then I reference the font in my Rakefile:

Motion::Project::App.setup do |app|
   # Use `rake config' to see complete project settings.
   app.name = 'myapp'
   app.fonts = ["OpenSans-Bold.ttf", "icomoon.ttf"]  

In my controller, I add a label to the screen using the icomoon font:

@lblIcon = UILabel.alloc.initWithFrame([[0,0],[100,100]])
@lblIcon.text = "A"
@lblIcon.backgroundColor = UIColor.clearColor
@lblIcon.color = "#ffffff".to_color
ico_font = UIFont.fontWithName("icomoon", size:48)
@lblIcon.font = ico_font
self.view.addSubview @lblIcon

Now, when I run rake clean to force a refresh and rake to launch the simulator, the font doesn't seem to work:

enter image description here

If I use the RubyMotion inspector/REPL and drill down on the font, it say it is loading Helvetica, not icomoon as I intended:

enter image description here

I'm at a loss here on why I can't apply the icomoon font family and helvetica appears instead.

Any suggestions or ideas?

share|improve this question
Have you tried app.fonts = ["OpenSans-Bold.ttf", "fonts/icomoon/icomoon.ttf"] –  Mikael Härsjö Jun 11 '13 at 8:24

1 Answer 1

I have added my fonts in the 'resources' folder and successfully using them directly without manipulating app.fonts:

b.titleLabel.font = UIFont.fontWithName('Entypo', size: barHeight*1.1)

(the font I'm using is called Entypo.ttf)

Otherwise, the code you've pasted looks ok to me.

share|improve this answer
Applying Entypo works! Maybe there some sort of font issue with the generated icomoon file? With that, Entypo looks like it uses unicode symbol codes instead of the alphabet - how do I use something like U+1F554 in my ruby string? @lblIcon.text = ["1F554".hex].pack("U") throws a NSInvalidArgumentException: NSConcreteMutableAttributedString addAttribute:value:range:: nil value –  Evan May 26 '13 at 14:45
What works for me is [0x1f554].pack('U*') –  Adrian Spinei May 26 '13 at 15:10
Hmm, is that b.titleLabel.text = [0x1f554].pack('U*')? Still get the exception with that syntax, but I'm 100% I'm using it right (haven't really gotten into this side of ruby) –  Evan May 26 '13 at 20:02
Looks like Using-a-unicode-character-in-a-UILabel-through-rubymotion pertains. –  Roger_S Aug 13 '13 at 22:19

Your Answer


