Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting the center point of an NSView

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

like image 510
foobar5512 Avatar asked Jul 03 '11 03:07

foobar5512


1 Answers

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.

like image 162
lmirosevic Avatar answered Oct 08 '22 13:10

lmirosevic