Skip to content

Instantly share code, notes, and snippets.

@DwightChan
Forked from aegzorz/CGRect+Additions.h
Created October 14, 2016 12:36
Show Gist options
  • Select an option

  • Save DwightChan/ccddd632f08d17643efadcf5189c77ed to your computer and use it in GitHub Desktop.

Select an option

Save DwightChan/ccddd632f08d17643efadcf5189c77ed to your computer and use it in GitHub Desktop.
Some functions for dealing with CGRects
static __inline__ CGRect CGRectFromCGSize( CGSize size ) {
return CGRectMake( 0, 0, size.width, size.height );
};
static __inline__ CGRect CGRectMakeWithCenterAndSize( CGPoint center, CGSize size ) {
return CGRectMake( center.x - size.width * 0.5, center.y - size.height * 0.5, size.width, size.height );
};
static __inline__ CGRect CGRectMakeWithOriginAndSize( CGPoint origin, CGSize size ) {
return CGRectMake( origin.x, origin.y, size.width, size.height );
};
static __inline__ CGPoint CGRectCenter( CGRect rect ) {
return CGPointMake( CGRectGetMidX( rect ), CGRectGetMidY( rect ) );
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment