Irshad Qureshi
Irshad Qureshi

Reputation: 819

Unable to show full image in a View Controller background

I am adding a background image in all of my view controllers but was unable to show full image only the top left portion is visible in the output, the code i am using is this

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

I am Putting this code in all my view controller's ViewDidLoad() function

Upvotes: 1

Views: 291

Answers (2)

Ashish Kakkad
Ashish Kakkad

Reputation: 23872

Try to use with CGImage of view

self.view.layer.contents = UIImage(named:"background.png").CGImage

Upvotes: 4

Dharmesh Kheni
Dharmesh Kheni

Reputation: 71854

I recommended you to do it this way:

Create UIImageView then add image in UIImageView.

let imageName = "night_sky_custom_background_by_rhuni-d5orpob.png"
let image = UIImage(named: imageName)
let imageView = UIImageView(image: image!)
imageView.frame = CGRect(x: 0, y: 0, width: self.view.bounds.size.height, height: self.view.bounds.size.height)
view.addSubview(imageView)

Upvotes: 1

Related Questions