我想将文本字符串的一部分加粗.
例如: 这是大胆的.这是正常的字符串.
在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)
归档时间: |
|
查看次数: |
9482 次 |
最近记录: |