Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add a image in background in my view in swift?

Tags:

swift

xcode6

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?

I'm trying make this with this code:

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

Thanks!

like image 648
user3745888 Avatar asked Jul 25 '14 07:07

user3745888


People also ask

How do you add a background in SwiftUI?

SwiftUI doesn't have a dedicated modifier for displaying background colors or images, but instead lets us specify any kind of background view using its background() modifier. To be clear, you can use any view as your background – another text view if you wanted, for example.


1 Answers

You should use UIColor init method:

view.backgroundColor = UIColor(patternImage: UIImage(named:imageName))
like image 90
Greg Avatar answered Oct 16 '22 16:10

Greg