菜鸟教程小白 发表于 2022-12-13 10:26:23

iOS:在 UIView 的中心绘制圆形的 UIImage


                                            <p><p>我有一个半径为 50 的圆形图像,现在我想将圆的中心与我的 View 的中心相同,如下所示:</p>

<pre><code>- (void)drawRect:(CGRect)rect {
    UIImage *arrow = ;
    ;
}
</code></pre>

<p>但是 drawAtPoint 不是在中心绘制。
我想知道如何定位图像的中心?这样我可以画吗?</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>来自 Apple 的 UIImage 文档</p>

<blockquote>
<p>This method draws the entire image in the current graphics context,
respecting the image’s orientation setting. In the default coordinate
system, images are situated down and to the right of the specified
point. This method respects any transforms applied to the current
graphics context, however.</p>
</blockquote>

<p>因此,将中心偏移一半的图像宽度和高度,以在 View 中心绘制图像的中心。</p>

<pre><code>- (void)drawRect:(CGRect)rect {
    CGSize imageSize = CGSizeMake(50,50);
    UIImage *arrow = ;
    ;
}
</code></pre></p>
                                   
                                                <p style="font-size: 20px;">关于iOS:在 UIView 的中心绘制圆形的 UIImage,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/29073786/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/29073786/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: iOS:在 UIView 的中心绘制圆形的 UIImage