Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MonoTouch: Where is Frame.Origin?

Tags:

I am trying to translate this centering code snip in Objective-C into MonoTouch

imageView.frame.origin.x = CGRectGetMidX(view.bounds) - 
            CGRectGetMidX(imageView.bounds)

But can't find where Origin is.

like image 382
Ian Vink Avatar asked Jan 11 '12 21:01

Ian Vink


1 Answers

MonoTouch maps GCRect to System.Drawing.RectangleF since it's closer to what .NET developers have been using (e.g. System.Drawing / Windows Forms...).

As such imageView.frame.origin.x will become imageView.Frame.Location.X which can simplified by imageView.Frame.X.

If you add using MonoTouch.CoreGraphics; to your source file you'll get extension methods that will provide you with CGRectGetMidX replacement, e.g.

views.Bounds.GetMidX ()

So

imageView.frame.origin.x = CGRectGetMidX(view.bounds) - CGRectGetMidX(imageView.bounds);

should become

imageView.Frame.X = view.Bounds.GetMidX () - imageView.Bounds.GetMidX ();
like image 84
poupou Avatar answered Nov 17 '22 05:11

poupou