Forum Xamarin.iOS

What is the correct way to use images from code?

MaruMaru DEMember ✭✭

Hi everyone!

I'm a little bit lost here so I hope you can help me.

I designed my UI images for @1x, @2x and @3x and load and display them from code. So for example for iPhone 6Plus one image is 1242px x 589px so it fills the whole width of the device.

The image is loaded from code like this: imageView.Image = UIImage.FromFile("myImagePath.png");
After this, I need to set the frame of the imageView: imageView.Frame = new CGRect(0, 0, imageView.Image.Size.Width, imageView.Image.Size.Height);
The problem with this is, as far as I understand it, that the Frame wants not pixels but points (so instead of a width of 1242 it wants 414).

So what do I need to do here? Scale the image down to 414 points? Sounds wrong to me to scale from pixels to points but when this is the way, please tell me. :)


Best Answer


  • MaruMaru DEMember ✭✭

    That makes so much sense now, thank you so much for giving me a very detailed answer!

Sign In or Register to comment.