7

i know this question repeat but i cant get sultion

I have this image

And i want view background like this

enter image description here

i have tried all the this

i also try this

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

Thank you in advance

EDIT :

 UIGraphicsBeginImageContext(self.view.frame.size)
 UIImage(named: "backgroundicon.png")?.draw(in: self.view.bounds)

 let image: UIImage = UIGraphicsGetImageFromCurrentImageContext()!

 UIGraphicsEndImageContext()

 self.view.backgroundColor = UIColor(patternImage: image)

Result :

enter image description here

Community
  • 1
  • 1
seggy
  • 1,176
  • 2
  • 18
  • 38
  • Take a look here http://stackoverflow.com/questions/38628803/how-to-set-background-image-in-swift – jonask Oct 20 '16 at 08:36

2 Answers2

8

Here is what you need,

self.imageView.image = UIImage(named: "abcd.png")!.resizableImage(withCapInsets: .zero)

Thats all buddy :)

iwasrobbed
  • 46,496
  • 21
  • 150
  • 195
Sandeep Bhandari
  • 19,999
  • 5
  • 45
  • 78
0

In your edit, I can see your last line

self.view.backgroundColor = UIColor(patternImage: image)

Shouldn't it be patternImage: backgroundicon.png

iwasrobbed
  • 46,496
  • 21
  • 150
  • 195
jonask
  • 679
  • 2
  • 6
  • 21