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

看板MacDev作者 (Tom Hsu)時間12年前 (2013/05/15 12:01), 編輯推噓1(101)
留言2則, 1人參與, 最新討論串4/4 (看更多)
UILabel *lbl = [[UILabel alloc] initWithFrame:CGRectMake(10 , 10, 300, 300)]; [lbl setFont:[UIFont boldSystemFontOfSize:30.0]]; NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:@"H2O"]; NSRange range = NSMakeRange(1, 1); UIFont *smallFont = [UIFont boldSystemFontOfSize:20.0]; NSDictionary *attr = @{(NSString*)kCTSuperscriptAttributeName : @(-1), (NSString*)kCTFontAttributeName : smallFont, NSForegroundColorAttributeName : [UIColor redColor]}; [string addAttributes:attr range:range]; lbl.attributedText = string; [self.view addSubview:lbl]; -- ★ ★ ██ █ █ 一眨眼間你又 CHECK IT OUT █ █ █ ◢█◣ ▄▌ 不要再看路過的女人們了 █▅ █▅█ ▌ ▌▄▌ ▁▁ ▁▁ ▁▁ █ █ █ ◥█◤ ▌ ◢▃▃▃▃▃▃▃▃▃▃▃▃█▃▎█ ▎█ ▎ ▎▃▃▃▃ ██ █ █ ▄ █ ▎█▁▎█▁▎ ▎ ◥▅▅▅ -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 211.75.166.176 ※ 編輯: tom19830924 來自: 211.75.166.176 (05/15 12:06)

05/15 21:48, , 1F
成功了,感謝tom19830924大
05/15 21:48, 1F

05/15 21:49, , 2F
改用 NSForegroundColorAttributeName 就成了
05/15 21:49, 2F
文章代碼(AID): #1HamYp0S (MacDev)
文章代碼(AID): #1HamYp0S (MacDev)