Getting the center point of an NSView

前端 未结 3 1598
既然无缘
既然无缘 2021-02-19 19:16

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

3条回答
  •  我寻月下人不归
    2021-02-19 19:34

    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.

提交回复
热议问题