我想将文本字符串的某些部分设为粗体。
例如:这要大胆。这是正常的字符串。
在Android中,可以使用跨度字符串轻松实现。在iOS中相当于什么?
是的,可以通过以下方法实现NSAttributedString
:
NSString *yourString = @"This is to be bold. This is normal string.";
NSMutableAttributedString *yourAttributedString = [[NSMutableAttributedString alloc] initWithString:yourString];
NSString *boldString = @"This is to be bold";
NSRange boldRange = [yourString rangeOfString:boldString];
[yourAttributedString addAttribute: NSFontAttributeName value:[UIFont boldSystemFontOfSize:12] range:boldRange];
[yourLabel setAttributedText: yourAttributedString];
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句