菜鸟教程小白 发表于 2022-12-13 02:05:36

ios - 如何阻止图像在 UIImageView 中缩放?


                                            <p><p>这是 Apple 的 cocoa-dev 邮件列表中的一位用户提出的问题,他认为我的回答对 Stack Overflow 会有所帮助:</p>

<blockquote>
<p>In XCode/IB, if add an Image View that has the Image property to an
image in my project it shows the image scaled to fit the Frame of the
Image View. How can I stop this and just truncate it? I want two
images on top of each other and just show the top half of one and the
bottom half of the other.</p>

<p>I see loads of scaling options in the “Content Mode” Property, but
nothing to say “none”. The closest I’ve managed so far is to set the
Content Mode to “Aspect Fit” and also set the clip to bounds. This
does what I want BUT the centre of the image shows, not the top, left.</p>

<p>Basically, I have two 24 x 24 images placed one on top of the other, I
want to show the first half (e.g. 0,0,24,12) of ImageA and the bottom
half of imageB (e.g. 0,12,24,12).</p>

<p>Can I do this in XCode/IB? If not can I do this in code?</p>
</blockquote></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>创建两个 ImageView ,将它们的大小设置为 24 x 12,并设置 <em>Clip To Bounds</em> 属性。</p>

<p>对于一个 View ,将其内容模式设置为顶部(== 顶部中心)或左上角,另一个 View 设置为底部(== 底部中心)或左下角。</p>

<p>如果您关闭剪辑属性,那么您将看到图像绘制在 ImageView 的边界之外。</p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - 如何阻止图像在 UIImageView 中缩放?,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/44976956/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/44976956/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - 如何阻止图像在 UIImageView 中缩放?