使用unicode的分数的NSString表示 [英] NSString representation of fractions using unicode

查看:179
本文介绍了使用unicode的分数的NSString表示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在我的iPhone应用程序很好显示分数。以前,我一直使用一个繁琐的switch语句导致硬编码unicode字符为粗俗部分,但我已经了解了unicode分数斜杠字符,如果我理解它正确,应该意味着我可以创建一个字符串如下: / p>

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 vulgar fractions, but I have learnt about the unicode fraction slash character which, if I am understanding it correctly, should mean that I can create a string as follows:

[NSString stringWithFormat:@"%i\u2044%i",numerator,denominator];

renderer会自动打印一个更小的超分子和下标分母。然而,上面的代码只是给我标准的1/2外观。我使用drawAtPoint将字符串放在屏幕上。我已经实验了decomposedStringUsingCanonicalMapping和precomposedStringUsingCanonicalMapping,但老实说文档失去了我。

And the "renderer" will automatically print it with a smaller, superscriped numerator and subscripted denominator. However, the above code just gives me the standard 1/2 appearance. I am using drawAtPoint to put the string on the screen. I have experimented with decomposedStringUsingCanonicalMapping and precomposedStringUsingCanonicalMapping but to be honest the documentation lost me.

这应该是工作还是NSString绘图不能处理这个?

Should this be working or does NSString drawing not cope with this?

推荐答案

我不知道unicode字符有任何方法有你描述的属性。 AFAIK区别U + 2044和正常斜线唯一的区别是它有点更有角度,两边没有空间,因此使它更靠近周围的数字。

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.

这是一个使用Fraction Slash的页面在HTML中,你可以看到它表明你只是得到类似1/10的东西,如果你尝试并自己使用它。它通过使用周围数字的HTML中的< sup> < sub> 标记来补偿得到一个合适的显示。

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 <sup> and <sub> tags in HTML on the surrounding numbers to get an appropriate display.

为了让你在NSString中工作,你必须找出一些方法来应用上标和下标到周围数字自己。

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.

这篇关于使用unicode的分数的NSString表示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆