Nirav Mehta Nirav Mehta -3 years ago 164
C# Question

How to set height width of imageview control in xamarin ios

I am new to Xamarin iOS development, and wanted to set background as an image of my view.

Is there any way to set background image directly to view?
or
Alternate solution to that is add ImageView control and set image property but in that case how to set height & width of the ImageView control programatically from ViewController.CS file?

Answer Source

In iOS there are two ways of defining the size of a control: AutoLayout or Springs & Struts. If you are using Auto Layout in your app (which you really should be), the size of the control can be defined by placing layout constraints on the control using Interface Builder, the Xamarin Studio designer, or programatically.

For Auto Layout:

  • Pin the leading and top edge of the imageView
  • set height and width constraints on the imageView

For Non-AutoLayout:

myImageView.Frame = new RectangleF(x-coordinate, y-coordinate, width, height);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download