ios - 如何为 UIView 制作基于图像的平铺背景,使其无法缩放?

标签 ios swift uiimage

在 iOS 应用程序中,我有 250x85pt UIView。我希望它有基于图像的平铺背景。原始图像为 398x398 像素。我希望平铺我的图像。

enter image description here

当我运行应用程序时,我的图像平铺,但由于某种原因它缩放如下:

enter image description here

我使用了下面的代码来实现它:

var image = UIImage(contentsOfFile: "myfilepath.png")!
var uicolor = UIColor(patternImage: image)
uiview.backgroundColor = uicolor

你能解释一下吗 1. 为什么 ios 缩放我的图像,以及 2. 如何在不缩放的情况下绘制平铺图像?

最佳答案

基本上图像比您的 UIView 大。当您提供 UIColor(patternImage: image) 时,它使用图像的 1 倍大小。 我们通常在笔记本电脑上使用的图像会根据其纵横比缩放到窗口大小。

所以根据您的要求缩放图像,然后将其用作背景图像。

关于ios - 如何为 UIView 制作基于图像的平铺背景,使其无法缩放?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29878371/

相关文章:

ios - 设置 CIFiltered UIImage 时 UIImageVIew 崩溃

javascript - 我的应用程序未触发事件设备就绪

ios - 从 iOS 应用程序创建帖子时,GPPShareBuilder 未设置 "PrefillText"

ios - 如何调试 navigationcontroller.tintColor 不改变?

ios - 更改 UIStackView 中 UIImageView 的高度优先级

swift - 在 Swift 中将 GPS 元数据写入 EXIF

ios - NSMutableURLRequest 将 '+' 替换为空格

ios - 动态 View 数的自动布局

ios - 如果字符串为 nil,则设置 NSNull()

iphone - 如何在一个 View 中显示两个图像 - iphone