Re: [問題] 請教一下ui介面有辦法寫出'上下標'嗎?
※ 引述《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
推
05/01 09:28, , 1F
05/01 09:28, 1F
討論串 (同標題文章)