菜鸟教程小白 发表于 2022-12-12 23:31:45

ios - 我希望我的文本在空白处通过扩展


                                            <p><p>我使用 <code>NSAttributeString</code> 在我的文本上设置删除线,我希望它在 <code>whitespace</code> 上扩展。</p>

<p>我已经设置了正确的范围,但是删除线只覆盖了文本字符。删除线是忽略空格,除非我在它之前和之后添加一些非空文本。</p>

<p>如何在没有额外文本的情况下在空白处扩展删除线?</p>

<p> <a href="/image/KQ3B1.png" rel="noreferrer noopener nofollow"><img src="/image/KQ3B1.png" alt="enter image description here"/></a> </p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>我今天遇到了同样的问题,现有的答案都没有给我一个我认为应该是直截了当的解决方案。经过一番研究,我找到了一个更简洁的使用 Unicode 字符的解决方案。</p>

<p>用一个或多个不间断的 Unicode 空格字符填充文本的每一侧 <code>(U+00A0)</code> 根据需要扩展行:</p>

<pre><code>let attributedText = NSAttributedString(
    string: &#34;\u{00A0}\(someText)\u{00A0}&#34;,
    attributes: [.strikethroughStyle: NSUnderlineStyle.single.rawValue]
)
</code></pre></p>
                                   
                                                <p style="font-size: 20px;">关于ios - 我希望我的文本在空白处通过扩展,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/41391129/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/41391129/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - 我希望我的文本在空白处通过扩展