如何在iOS中使字符串的一部分变为粗体?

WIS*_*SHY 9 string ios

我想将文本字符串的一部分加粗.

例如: 这是大胆的.这是正常的字符串.

在Android中,可以通过使用spannable字符串轻松实现.在iOS中它的等价物是什么?

Abh*_*hek 24

是的,可以通过以下方式实现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];
Run Code Online (Sandbox Code Playgroud)