1

I am able to successfully subscript numbers by using:

static const unichar kSubscriptZero = 0x2080;
int numberOfHydrogens = 2;
NSString *water = [NSString stringWithFormat:@"H%CO",
    kSubscriptZero + numberOfHydrogens];

The above code prints out a nicely formatted > H2O (with of course the 2 as subscript), I am having an issue doing the same with other unicode characters (that are not numbers) for example the 209Cwhich is a subscript t. Instead of my subscript t, i get a square box... can someone please tell me the right way this can be done?

vzm
  • 2,440
  • 6
  • 28
  • 47

1 Answers1

1

If you get a square box instead of the desired glyph then the font does not have a glyph for that character and therefore cannot display it.

If you don't find a font containing U+209C (LATIN SUBSCRIPT SMALL LETTER T) then the only alternative probably is to use attributed strings, as suggested in this answer: https://stackoverflow.com/a/17957628/1187415.

Community
  • 1
  • 1
Martin R
  • 529,903
  • 94
  • 1,240
  • 1,382
  • 1
    The set of fonts containing e.g. U+209C is small, not much larger than the list at http://www.fileformat.info/info/unicode/char/209c/fontsupport.htm (DejaVu fonts and a few other fonts). – Jukka K. Korpela Jul 31 '13 at 18:31
  • @JukkaK.Korpela: Thank you for the link, that might be useful some time! - As it seems no OS X or iOS Font is on that list. – Martin R Jul 31 '13 at 18:36
  • Most of the fonts in the list are free fonts, which should work on OS X and iOS, too (though they need to be downloaded or installed, or distributed along with an application and installed by the user). – Jukka K. Korpela Jul 31 '13 at 18:44