20

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.

1 Answer 1

41

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 ();
1
  • Does CGRect.Size.Width maps with CGRect.Width also?
    – mr5
    May 31, 2017 at 8:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.