Re: [問題] 請教一下ui介面有辦法寫出'上下標'嗎?

看板MacDev作者 (Bang!)時間11年前 (2013/04/11 05:27), 編輯推噓1(100)
留言1則, 1人參與, 最新討論串2/4 (看更多)
※ 引述《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
感謝:D
05/01 09:28, 1F
文章代碼(AID): #1HPTb6PP (MacDev)
討論串 (同標題文章)
文章代碼(AID): #1HPTb6PP (MacDev)