作者ksksBangBang (Bang!)
看板MacDev
标题Re: [问题] 请教一下ui介面有办法写出'上下标'吗?
时间Thu Apr 11 05:27:32 2013
※ 引述《donkeychen (Bad_To_The_Bone)》之铭言:
: 大家好
: 想请教一下如果需要把
: a 的 b 次方
: 或者是想打出
: a1 a2 a3 ...
: 类似的数学符号
: 在xcode里面有办法设定吗?
: 感谢
请使用NSAttributedString
设定kCTSuperscriptAttributeName (正值上标 负值下标)
范例:
#import <CoreText/CoreText.h>
#import <CoreText/CTStringAttributes.h>
NSMutableAttributedString *string =
[[NSMutableAttributedString alloc] initWithString:@"H2O"];
NSRange range = NSMakeRange(1, 1);
UIFont *smallFont = [UIFont systemFontOfSize:8.0];
NSDictionary *attr = @{(NSString*)kCTSuperscriptAttributeName:@(-1),
(NSString*)kCTFontAttributeName:smallFont};
[string setAttributes:attr range:range];
yourLabel.attributedText = string;
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 199.2.242.199
1F:推 donkeychen:感谢:D 05/01 09:28