gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-02 10:23:09 27 4
gpt4 key购买 nike

这是一个用户在 Apple 的 cocoa-dev 邮件列表上提出的问题,他认为我的回答对 Stack Overflow 有帮助:

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.

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.

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).

Can I do this in XCode/IB? If not can I do this in code?

最佳答案

创建两个 ImageView ,将它们的大小设置为 24 x 12,并设置 Clip To Bounds 属性。

对于一个 View ,将其内容模式设置为顶部(== top-center)或左上,另一个设置为底部(== bottom-center)或左下。

如果您关闭 clip 属性,您将看到图像绘制在 ImageView 的边界之外。

关于ios - 如何阻止图像在 UIImageView 中缩放?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44976956/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com