作者tom19830924 (Tom Hsu)
看板MacDev
标题Re: [问题] 请教一下ui介面有办法写出'上下标'吗?
时间Wed May 15 12:01:48 2013
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)
1F:推 bloodera:成功了,感谢tom19830924大 05/15 21:48
2F:→ bloodera:改用 NSForegroundColorAttributeName 就成了 05/15 21:49