uiview – 如何在swift中将背景图像设置为colorWithPatternImage
发布时间:2020-12-14 06:04:39 所属栏目:百科 来源:网络整理
导读:我的问题是,有可能有一个UIView显示图像,如果是这样,我怎么做呢?所有我可以找到的colorwithpatternImage不再使用swift。 我现在想使用的代码是: self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"background.png"]];
我的问题是,有可能有一个UIView显示图像,如果是这样,我怎么做呢?所有我可以找到的colorwithpatternImage不再使用swift。
我现在想使用的代码是: 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 *)图像返回一个UIColor实例,因此它将成为Swift中的一个便利初始化程序。类似地,UIImage imageNamed:变为init(patternImage image:UIImage!)。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |