I am trying to set the width of an image dynamically using MonoTouch. I have added the image to the view using Xcode Interface Builder.
What I want to do is keep the X and Y values of the image exactly the same. I just want the width of the image to change depending on a float value.
Example: If I placed the the image on the view at X = 50 and Y = 50 and the image size is W = 100 and H = 100 then I want to change the width dynamically based on conditions. I have tried to set the images’ width dynamically like this:
img.Bounds.Width = 150;
and like this
img.Bounds.Size.Width = 150;
I have also tried to create a new RectangleF and setting the bounds equal to that Rectangle like this
RectangleF fillrect = new RectangleF(50, 50,
150, img.Bounds.Height);
and then setting the image bounds to that rectangle like this:
img.Bounds = fillrect;
The above method sizes the image but then moves the image to the incorrect place (X and Y values).
I have also tried various methods using SizeF but to no avail.
How can I just set the width of the image and keep it in the same place I placed it on interface builder?
And also how to change the X and Y values so that I can move another image based on the growth of the aforementioned image.
Seems like changing of Bounds applies around the Center of the view.
Try to set new Frame instead:
Location will be the same, but Size will be changed.