简体   繁体   English

如何在我的视图中在swift中添加背景图像?

[英]How to add a image in background in my view in swift?

I'm trying add a image background in my viewController of my Swift app, but colorWithPatternImage is unavailable.. there are other form for this or is necessary add this into a imageView? 我正在尝试在我的Swift应用程序的viewController中添加图像背景,但colorWithPatternImage不可用..还有其他形式或者必须将其添加到imageView中吗?

I'm trying make this with this code: 我正在尝试使用此代码:

 let imageName = "image.png"
    self.view.backgroundColor = UIColor.colorWithPatternImage(UIImage(named:imageName))

Thanks! 谢谢!

您应该使用UIColor init方法:

view.backgroundColor = UIColor(patternImage: UIImage(named:imageName))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在Swift中将背景图像添加到UICollectionViewCell? - How to add a background image to a UICollectionViewCell in Swift? Swift,如何调整图像大小、添加填充和背景? - Swift, how to resize, add padding and background to an image? 如何使用Swift将相同的背景图像添加到ios应用程序的所有视图中? - How can I add the same background image to all views in my ios app using swift? 如何在 SwiftUI 中添加背景图像以完成视图 - How to add background image to complete view in SwiftUI 我的uiwebview开始加载时使用Swift添加自定义背景图像 - Add a custom background image as my uiwebview starts to load (using Swift) Swift:如何将图标图像和图像背景添加到 App 委托中的 UItabBar? - Swift : How to add icon image and image background to the UItabBar in App delegate? 在 swift 中居中图像并添加背景 - Center image and add background in swift 如何使用Swift在现有图像中添加背景色? - How to add background colour in existing image using Swift? 如何在 swift 的 canvasView(由 PencilKit 制作)中添加背景图像? - How can I add background image into canvasView(made by PencilKit) in swift? 如何使用Swift将背景图片和标签添加到UIBarButtonItem - How do I add a background image and label to a UIBarButtonItem using Swift
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM