gpt4 book ai didi

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

转载 作者:IT王子 更新时间:2023-10-29 05:49:23 25 4
gpt4 key购买 nike

在 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/

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