Skip to content

Instantly share code, notes, and snippets.

@psobko
Created February 7, 2014 17:44
Show Gist options
  • Save psobko/8867811 to your computer and use it in GitHub Desktop.
Save psobko/8867811 to your computer and use it in GitHub Desktop.
Get the center of a CGRect
CGPoint (^CGRectGetCenter)(CGRect) = ^(CGRect rect)
{
return CGPointMake(CGRectGetMidX(rect), CGRectGetMidY(rect));
};
@ezefranca
Copy link

ezefranca commented Dec 11, 2021

Swift 5 version:

// Center point of a CGRect 

extension CGRect {
    var center : CGPoint {
        return CGPoint(x: self.midX, y: self.midY)
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment