html - 如何在 iOS 中为 html 格式的字符串应用粗体?
<p><p>我想使用在我的应用程序的撰写邮件中打印的字符串以粗体打印文本</p>
<pre><code>messageBody = ;
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><pre><code>What you could do is use an NSAttributedString.
NSString *boldFontName = [ fontName];
NSString *yourString = ...;
NSRange boldedRange = NSMakeRange(22, 4);
NSMutableAttributedString *attrString = [ initWithString:yourString];
;
[attrString addAttribute:kCTFontAttributeName
value:boldFontName
range:boldedRange];
;
//draw attrString here...
or
use this code
you do not want to bother with fonts (as not every variation of font contains "Bold"), here is another way to do this:
NSMutableAttributedString *attrString = [ initWithString:"Approximate Distance: 120m away"];
;
[attrString applyFontTraits:NSBoldFontMask
range:NSMakeRange(22, 4)];
;
</code></pre></p>
<p style="font-size: 20px;">关于html - 如何在 iOS 中为 html 格式的字符串应用粗体?,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/26915376/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/26915376/
</a>
</p>
页:
[1]