Reputation: 819
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
Reputation: 23872
Try to use with CGImage
of view
self.view.layer.contents = UIImage(named:"background.png").CGImage
Upvotes: 4
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