Getting the center point of an NSView

foobar5512 picture foobar5512 · Jul 3, 2011 · Viewed 7.3k times · Source

I need to get the center point of a NSView in the form of a CGPoint, how can I achieve this? I am basically looking for the equivalent of the UIKit, UIView.center

Answer

lms picture lms · Feb 11, 2013

A simple and easy to read way is:

CGPointMake(NSMidX(myView.frame), NSMidY(myView.frame))

I would suggest making this code, a category on NSView with a read only property named center.