菜鸟教程小白 发表于 2022-12-12 11:26:05

iphone - CGContextShowText 以中心对齐方式绘制


                                            <p><p>尝试使用 CGContextShowText 绘制文本。如何使文本居中于特定矩形?</p>

<p>注意:drawInRect 可以完成这项工作。我特别询问 CGContextShowText</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>如果你真的想使用 <code>CGContextShowText</code>(Core Text 会更好),你必须自己做数学,即计算出文本有多大,然后减去一半您的中心点的 x 坐标。</p>

<p>要确定文本的大小,可以将文本绘制模式设置为<code>kCGTextInvisible</code>(使用<code>CGContextSetTextDrawingMode</code>),绘制一次文本,检查文本位置的距离已移动(在绘制前后使用<code>CGContextGetTextPosition</code>),然后在正确的位置以可见的绘制模式再次绘制文本。</p></p>
                                   
                                                <p style="font-size: 20px;">关于iphone - CGContextShowText 以中心对齐方式绘制,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/16852005/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/16852005/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: iphone - CGContextShowText 以中心对齐方式绘制