【发布时间】:2013-04-05 06:57:22
【问题描述】:
我希望 UILabel 的第一个字母的字体大小与其他字母不同,大一些。需要一些关于如何做到这一点的指导。标签有很多字。
这是我尝试过的:
NSArray * words = [Label.text componentsSeparatedByCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
NSString *firstLetter = [[words objectAtIndex:0] substringToIndex:1];
但被困在增加 NSString 的大小上。有没有更好的办法?欢迎提出建议和指导..谢谢..
编辑:
[Label setFont:[UIFont fontWithName:@"Arial" size:12.f]];
NSArray * words = [Label.text componentsSeparatedByCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
UIFont *fontFirst=[UIFont fontWithName:@"Arial" size:15.f];
NSDictionary *attrsDictFirst=[NSDictionary dictionaryWithObject:font forKey:NSFontAttributeName];
NSAttributedString *finalString=[[NSAttributedString alloc] initWithString:[[words objectAtIndex:0] substringToIndex:1] attributes:attrsDictFirst];
【问题讨论】:
-
如果您只需要 iOS 6 或更高版本,请使用
UILabel attributedText。如果您需要支持 iOS 5 或更早版本,那么UILabel中的字体不能超过一种。 -
我怀疑你必须使用属性文本。 (或者把它分成两个标签。)