【发布时间】:2011-11-14 15:23:21
【问题描述】:
我有一个包含中英文字符的 UILabel,
现在我想设置一种中文字体和另一种英文字体,
如何做到这一点?
【问题讨论】:
标签: iphone ios fonts uikit uilabel
我有一个包含中英文字符的 UILabel,
现在我想设置一种中文字体和另一种英文字体,
如何做到这一点?
【问题讨论】:
标签: iphone ios fonts uikit uilabel
我不相信这是可能的。在UILabel 中设置的font 属性将应用于该UILabel 的text 属性中指定的整个字符串。
【讨论】:
通常一个标签只能有一种字体。尽管如此,如果您想为不同的语言显示不同的字体,则可以将不同的语言字符串保留在不同的标签中并按照您想要的方式排列它们。
查看此内容以确定标签的大小。
Resize UITableViewCell to UILabel's height dynamically
这也很有帮助。
How do I wrap text in a UITableViewCell without a custom cell
【讨论】:
【讨论】:
我没有尝试过使用中文字体,但是您可以使用以下代码使用 NSMutableAttributedString 在标签上设置不同/多种字体和其他属性。 Foll 是我的代码:
UIFont *ArialFont = [UIFont fontWithName:@"arial" size:18.0];
NSDictionary *arialdict = [NSDictionary dictionaryWithObject: ArialFont forKey:NSFontAttributeName];
NSMutableAttributedString *AattrString = [[NSMutableAttributedString alloc] initWithString:title attributes: arialdict];
UIFont *VerdanaFont = [UIFont fontWithName:@"verdana" size:12.0];
NSDictionary *veradnadict = [NSDictionary dictionaryWithObject:VerdanaFont forKey:NSFontAttributeName];
NSMutableAttributedString *VattrString = [[NSMutableAttributedString alloc]initWithString: newsDate attributes:veradnadict];
[VattrString addAttribute:NSForegroundColorAttributeName value:[UIColor blackColor] range:(NSMakeRange(0, 15))];
[AattrString appendAttributedString:VattrString];
lblText.attributedText = AattrString;
请注意,lblText 是 UILabel,作为文件所有者的出口。 可以继续添加他想要的任意数量的 NSMutableAttributedString。
另外请注意,我在我的项目中添加了 verdana 和 arial 字体并为此添加了 plist。
【讨论】: