Hey Guys i´m new to MonoTouch and have a problem. Can anyone of you tell me how to set the Position of a subview? I tried this:
UIImageView imageview = new UIImageView(this.ImageSource);
this.AddSubview(imageview);
this.Subviews[0].Bounds.X = 30;
I hope anyone of you can help me.
Thanks
The
Bounds
property gives you, well, the bounds of the view. If you want to reposition it, use:or
Beside
Bounds
orFrame
(mentioned by @Krumelur) there's a .NET issue in your code.RectangleF
is a value-type (struct), not a reference type. You cannot change their properties / fields in .NET without creating a new instance (directly or indirectly);i.e. the property getter for
Bounds
will always return a new instance. So you assignment of 30 is done on an instance different than the oneSubviews[0]
is using.Proof:
So what you need to do in such case is:
So the new
RectangleF
(struct) instance is assigned back to theBounds
property (with the new value you set).