NSString中的上标序数后缀 [英] Superscripted ordinal suffix in NSString
问题描述
NSString中是否有一种方法来输出st,nd和rd,但是采用上标格式?任何已知的unicode可能?
Is there a way in NSString to output the st, nd, and rd but in a superscripted format? Any known unicode perhaps?
推荐答案
似乎没有任何Unicode字符,但它很容易做一个 NSAttributedString
将会执行的操作:
There doesn't seem to be any Unicode characters for this, but it's easy enough to make an NSAttributedString
that will do the trick:
NSDictionary * superscriptAttrs = [NSDictionary dictionaryWithObject:[NSNumber numberWithInt:1]
forKey:NSSuperscriptAttributeName];
NSAttributedString * st = [[NSAttributedString alloc] initWithString:@"st"
attributes:superscriptAttrs];
NSMutableAttributedString * premiere = [[NSMutableAttributedString alloc] initWithString:@"1"];
[premiere appendAttributedString:st];
// Don't forget to release everything when you're done with it!
您可能还需要更改上标的字体大小。这是通过将属性字典中的 NSFontAttributeName
包含在适当的字体对象中来实现的。请注意, NSAttributedString
仅适用于iOS 4.0+以上版本的iPhone,以及iPad版本3.2+(见注释)。
You might also want to change the font size of the superscript. This is accomplished by including the NSFontAttributeName
in the attributes dictionary with an appropriate font object. Note that NSAttributedString
is only available on the iPhone in iOS 4.0+, and on the iPad in 3.2+ (see comment).
这篇关于NSString中的上标序数后缀的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!