sam
sam

Reputation: 87

how to Fit image view in the Screen in all iPhoneScreens

I have created image-view programmatically with constraints

let imgName = "2017-01-18-2.png"
    let image = UIImage(named: imgName)
    let imgView = UIImageView(image: image!)

    imgView.frame = CGRect(x: 0, y: 0, width: 365, height: 667)
    view.addSubview(imgView)

But when im running in iPhone 5s its coming with full view (Full view Image) If I'm running in iPhone 7 its coming lil bit up (LilbitUp Image) I have searched all previous questions but all people saying create constraints in storyboard but I want to do with programatically If any help It would be appreciated Thank you in Advance

Upvotes: 3

Views: 78

Answers (2)

santoshi
santoshi

Reputation: 380

In Objective-c

UIview.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)

Upvotes: 2

santoshi
santoshi

Reputation: 380

Try this

imgView.frame = CGRect(x: 0, y: 0, width: view.frame.width, height: view.frame.hight)

Upvotes: 4

Related Questions