NSString representation of fractions using unicode

前端 未结 4 1649
傲寒
傲寒 2021-01-12 15:42

I am trying to \"nicely\" display fractions in my iPhone application. Previously I have been using a tedious switch statement leading to hardcoded unicode characters for the

4条回答
  •  逝去的感伤
    2021-01-12 16:18

    I'm not aware of any way for a unicode character to have the properties you describe. AFAIK the only thing that distinguishes U+2044 from a regular slash is it's a bit more angled and has little-to-no space on either side, therefore making it nestle up a lot closer to the surrounding numbers.

    Here's a page on using the Fraction Slash in HTML, and as you can see it demonstrates that you simply get something like "1⁄10" if you try and use it on your own. It compensates for this by using the and tags in HTML on the surrounding numbers to get an appropriate display.

    In order for you to get this to work in NSString you're going to have to figure out some way to apply superscripting and subscripting to the surrounding numbers yourself.

提交回复
热议问题