gpt4 book ai didi

uiview - 如何在 swift 中将背景图像设置为 colorWithPatternImage

转载 作者:IT王子 更新时间:2023-10-29 05:00:28 32 4
gpt4 key购买 nike

我的问题是,是否可以让 UIView 显示图像,如果可以,我该怎么做?我所能找到的只是不再适用于 swift 的 colorwithpatternImage

我现在尝试使用的代码是:

self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"background.png"]];  

预先感谢您的回答!

最佳答案

引用UIColor documentation .

在 Swift 中,你必须调用便利初始化器。这是因为在 Swift 中,所有返回其类实例的 Objective-C 类方法都变成了便利初始化器。

这是它在 Swift 中的样子:

 self.view.backgroundColor = UIColor(patternImage: UIImage(named: "background.png"))

+ (UIColor *)colorWithPatternImage:(UIImage *)image 返回一个 UIColor 实例,因此它将成为 Swift 中的便利初始化器。同样,UIImage imageNamed: 变为 init(patternImage image: UIImage!)

关于uiview - 如何在 swift 中将背景图像设置为 colorWithPatternImage,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25106784/

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