3 回答
TA贡献1818条经验 获得超7个赞
您可以做的是使用NSAttributedString。
NSString *boldFontName = [[UIFont boldSystemFontOfSize:12] fontName];
NSString *yourString = ...;
NSRange boldedRange = NSMakeRange(22, 4);
NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc] initWithString:yourString];
[attrString beginEditing];
[attrString addAttribute:kCTFontAttributeName
value:boldFontName
range:boldedRange];
[attrString endEditing];
//draw attrString here...
看看这个方便的花哨的指南,NSAttributedString用Core Text 绘制对象。
TA贡献1834条经验 获得超8个赞
如果您不想打扰字体(因为并非每个字体的变体都包含“粗体”),这是另一种方法。请注意,这仅在OS X上可用...:
NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc] initWithString:"Approximate Distance: 120m away"];
[attrString beginEditing];
[attrString applyFontTraits:NSBoldFontMask
range:NSMakeRange(22, 4)];
[attrString endEditing];
- 3 回答
- 0 关注
- 612 浏览
添加回答
举报