菜鸟教程小白 发表于 2022-12-11 19:06:19

html - 使用指定字体在 UILabel 中显示 html 标签


                                            <p><p>如何在<code>UILabel</code>中的文字下方显示</p>

<pre><code>While &lt;em&gt;La La Land &lt;/em&gt;is a film emphasising the problems
</code></pre>

<p>我尝试使用下面的代码,但是当与指定字体一起使用时,它没有显示 <code><em></code> 标签内的正确文本格式(斜体渲染)。</p>

<pre><code>NSMutableAttributedString *attrHTMLText = [ initWithData: options:@{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType,NSCharacterEncodingDocumentAttribute: @(NSUTF8StringEncoding)} documentAttributes:nil error:nil];
;
range:NSMakeRange(0, attrHTMLText.length)];
Label.attributedText = attrHTMLText;
</code></pre></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>如果你想让文本的某些部分变成斜体,你可以使用 <code>NSMutableAttributedString</code></p> <pre><code>NSMutableAttributedString *strText = [ initWithString:@&#34;While La La Land is a film emphasising the problems&#34;];
[strText addAttribute:NSFontAttributeName
            value:
            range:NSMakeRange(7, 16)];
;
</code></pre></p>
                                   
                                                <p style="font-size: 20px;">关于html - 使用指定字体在 UILabel 中显示 html 标签,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/42505536/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/42505536/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: html - 使用指定字体在 UILabel 中显示 html 标签