0

In my Swift app i have inserted an image like this:

let ImageNavig = "5.jpg"
        let image1 = UIImage(named: ImageNavig)
        let image1View = UIImageView(image: image1!)
        let yCenter1 = self.view.center.y
        let Image1Size = CGPoint(x: 420, y: 240)
        image1View.frame = CGRect(x: 0, y: -10, width: Image1Size.x, height: Image1Size.y)
        view.addSubview(image1View)

but, when I run the project with older Iphone the results is this: enter image description here

how can I insert autolayout programmatically without storyboard?

  • Does this answer your question? [How to add constraints programmatically using Swift](https://stackoverflow.com/questions/26180822/how-to-add-constraints-programmatically-using-swift) – NicolasElPapu Apr 23 '20 at 13:28

1 Answers1

0

If you have issue of image width in old iphones then it is because, you have given fix width to the image , use below code it will take width dynamically as per iphone width

let Image1Size = CGPoint(x: self.view.frame.width, y: 240)

instead of

let Image1Size = CGPoint(x: 420, y: 240)
Dhara Patel
  • 396
  • 3
  • 9