Reputation: 5896
I am trying to set up my background photo to the view,
the img
dimention is 1900x1000
. It's showing only small part of the image and does not fit it in.
This is what I have tried :
let image1 = UIImage(named: "1.jpg")
let imageview = UIImageView(image: image1)
imageview.contentMode = UIViewContentMode.ScaleAspectFill
self.view.addSubview(imageview)
2) for some reason after I set the background image the label that was in the view "disappear", my guess it that its behind the background image, how can I set it to be at the front?
Upvotes: 1
Views: 4980
Reputation: 66302
ScaleAspectFill
will fill imageview
's frame
while maintaining the aspect ratio of the image. So if the image is the wrong size, you need to change imageview
's frame
or autolayout constraints.
Regarding question #2, addSubview(_:)
adds the subview to the front.
You could instead use insertSubview(_:belowSubview:)
to place imageview
below your label. Alternatively, you could pass your label into bringSubviewToFront(_:)
.
Upvotes: 2