Skip to content

Instantly share code, notes, and snippets.

@bdalziel
Created October 22, 2016 16:55
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 bdalziel/335723f7871500182b34fb3207401f10 to your computer and use it in GitHub Desktop.
Save bdalziel/335723f7871500182b34fb3207401f10 to your computer and use it in GitHub Desktop.
// Between Title and Description
// 1. Get height below title baseline which is poking out below a grid line - get the value that would make this poke a whole 8 px.
CGFloat titleDescenderRoundedToNextGridline = 8 - fmod([ASPFontUtil getUITextElementBelowBaselineHeight:ASPUITextElementContentCardTitle traitCollection:contextTraitCollection], 8) ;
// 2. Get height above description baseline that is poking above a grid line - get the value that would make this poke a whole 8 px.
CGFloat descriptionAscenderRoundedToNextGridline = 8 - fmod([ASPFontUtil getUITextElementAboveBaselineHeight:ASPUITextElementContentCardDescription traitCollection:contextTraitCollection], 8) ;
// 3. Round sum of nudges (top and bottom), and make sure we're not putting more than a single grid spacing between them
CGFloat belowTitleMargin = [ASPUtil roundToSubPixelPrecision:titleDescenderRoundedToNextGridline + descriptionAscenderRoundedToNextGridline deviceScale:deviceScale];
if (belowTitleMargin > 8.0) {
belowTitleMargin = fmod(belowTitleMargin, 8);
}
self.constraintBelowTitle.constant = belowTitleMargin;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment