【发布时间】:2012-10-10 01:27:00
【问题描述】:
我正在深入研究 iOS 上的 NSAttributedStrings。我有一个模型返回一个人的名字和姓氏为NSAttributesString。 (我不知道在模型中处理属性字符串是否是个好主意!?)我希望定期打印名字,而姓氏应该以粗体打印。我不想要的是设置文本大小。到目前为止,我发现的是:
- (NSAttributedString*)attributedName {
NSMutableAttributedString* name = [[NSMutableAttributedString alloc] initWithString:self.name];
[name setAttributes:@{NSFontAttributeName : [UIFont boldSystemFontOfSize:[UIFont systemFontSize]]} range:[self.name rangeOfString:self.lastname]];
return name;
}
但是,这当然会覆盖姓氏的字体大小,这在UITableViewCell 中看起来非常有趣,其中名字将以单元格标签的常规文本大小打印,最后一个name 会打印得很小。
有什么方法可以实现我想要的吗?
感谢您的帮助!
【问题讨论】:
标签: iphone ios ipad uifont nsattributedstring