Skip to content

Instantly share code, notes, and snippets.

@jfuellert
Created January 6, 2016 16:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jfuellert/5bb0418871f0e30070aa to your computer and use it in GitHub Desktop.
Save jfuellert/5bb0418871f0e30070aa to your computer and use it in GitHub Desktop.
Returns a centered position CGRect for a given CGRect inside of a larger CGRect
/** Returns a centered position CGRect for a given CGRect inside of a larger CGRect */
CGRect centeredRect(CGRect outerRect, CGRect innerRect) {
CGRect centeredRect = innerRect;
centeredRect.origin.x = CGRectGetMidX(outerRect) - (CGRectGetWidth(innerRect) * 0.5f);
centeredRect.origin.y = CGRectGetMidY(outerRect) - (CGRectGetHeight(innerRect) * 0.5f);
return centeredRect;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment