UIViewContentModeScaleAspectFit 和 UIViewContentModeScaleToFill 之间的区别?

发布于 2024-10-15 17:53:41 字数 115 浏览 4 评论 0原文

UIViewContentModeScaleAspectFitUIViewContentModeScaleToFill 之间有什么区别...?

what is the difference between UIViewContentModeScaleAspectFit and UIViewContentModeScaleToFill...?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

紫瑟鸿黎 2024-10-22 17:53:41

您可以在此处查看内容模式之间的差异:

在此处输入图像描述

重绘模式与“缩放到填充”模式一样工作。
但当视图几何形状发生变化时,它们的绘制方式有所不同。
缩放至填充模式使用已渲染的内容,而重绘模式则再次渲染内容。

You can see the differences between the content modes here:

enter image description here

Redraw mode works as Scale to Fill mode.
But there is a difference in how they are drawn when view geometry changes.
Scale to Fill mode uses already rendered content while Redraw mode renders the content again.

鲜肉鲜肉永远不皱 2024-10-22 17:53:41

如果您正在谈论UIViewContentMode,以下内容来自文档

UIViewContentModeScaleToFill

如有必要,可通过更改内容的纵横比来缩放内容以适合其自身大小。

UIViewContentModeScaleAspectFit

通过保持纵横比来缩放内容以适应视图的大小。视图边界的任何剩余区域都是透明的。

UIViewContentModeScaleAspectFill

缩放内容以填充视图的大小。内容的某些部分可能会被剪切以填充视图的边界。

If you are talking about UIViewContentMode, the following is from the Doc.

UIViewContentModeScaleToFill

Scales the content to fit the size of itself by changing the aspect ratio of the content if necessary.

UIViewContentModeScaleAspectFit

Scales the content to fit the size of the view by maintaining the aspect ratio. Any remaining area of the view’s bounds is transparent.

UIViewContentModeScaleAspectFill

Scales the content to fill the size of the view. Some portion of the content may be clipped to fill the view’s bounds.

如果没结果 2024-10-22 17:53:41

UIImageView 和 contentMode

当我们处理某些内容(例如图像)时,实际上我们有两个矩形 - 图像(内容,位图)和视图(框架)

例如我们有图像(黑色圆圈 800x800 px)或图像(蓝色圆圈25x25像素)和UIImageView(240x120点)[iOS像素,点,单位]

这里的问题是如何在视图内显示图像,这就是为什么我们有 contentMode 来调整结果

我们有下一个主要选项:

.scaleAspectFit - (by default for UIImageView) scale image with saving aspect ratio to fit in view(set max image side to min view side)
.scaleAspectFill - scale image with saving aspect ratio to fill a view(set min image side to max view side)

.scaleToFill - scale image without saving aspect ratio to fill a view(set image size to view size)

.top - positioning original image at top 
.bottom
.left
.right
.center
.topLeft
.topRight
.bottomLeft
.bottomRight

.redraw - uses for custom view to call `drawRect` method  when size is changed

注意:

  • 当图像大于视图时,您可以使用 uiImageView.clipsToBounds< 隐藏和显示额外内容

  • a href="https://stackoverflow.com/a/73513083/4770877">[关于]在未设置 UIImageView 大小的情况下 [内在内容大小] - contentMode 不会产生任何效果 - 视图将具有与图像相同的大小

[iOS 边界和框架]

UIImageView and contentMode

When we work with some content(e.g. image) actually we have two rectangles - image(content, bitmap) and view(frame)

For example we have image(black circle 800x800 px) or image (blue circle 25x25 px) and UIImageView(240x120 points) [iOS pixels, points, units]

The problem here is how to show image inside view, that is why we have contentMode to adjust the result

We have next main options:

.scaleAspectFit - (by default for UIImageView) scale image with saving aspect ratio to fit in view(set max image side to min view side)
.scaleAspectFill - scale image with saving aspect ratio to fill a view(set min image side to max view side)

.scaleToFill - scale image without saving aspect ratio to fill a view(set image size to view size)

.top - positioning original image at top 
.bottom
.left
.right
.center
.topLeft
.topRight
.bottomLeft
.bottomRight

.redraw - uses for custom view to call `drawRect` method  when size is changed

Notes:

  • when image is bigger then view you can use uiImageView.clipsToBounds[About] to hide and show extra content

  • if you don't set UIImageView size[Intrinsic Content Size] - contentMode will no have an effect - view will have the same size as an image

[iOS Bounds and Frame]

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文