我想将文本字符串的一部分加粗.
例如:这是大胆的.这是正常的字符串.
在Android中,可以通过使用spannable字符串轻松实现.在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];