Skip to content

Instantly share code, notes, and snippets.

@bdalziel
Created October 22, 2016 16:41
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/257abc42cc3458c381aa96917bf11077 to your computer and use it in GitHub Desktop.
Save bdalziel/257abc42cc3458c381aa96917bf11077 to your computer and use it in GitHub Desktop.
// 1. We're trying to align the baseline of the description label with a gridline this far from the bottom of the Content Card
CGFloat targetBottomMargin = smallMargin;
// 2. We need to know how far to nudge the label down. This is a calculation dependent on the UI traits, and is specific to the typography we're using for the description label
CGFloat descriptionLabelBaselineAdjustmentHeight = [ASPFontUtil getUITextElementBelowBaselineHeight:ASPUITextElementContentCardDescription traitCollection:contextTraitCollection];
// 3. Font measurements aren't nice round numbers. I have a utility to round floats to numbers the UI can resonable render at (sub pixel), which is dependent on device scale
CGFloat bottomMargin = [ASPUtil roundToSubPixelPrecision:(targetBottomMargin - descriptionLabelBaselineAdjustmentHeight) deviceScale:deviceScale];
// 4. Use our dynamically adjusted bottom margin and hope it works
self.contentCard.layoutMargins = UIEdgeInsetsMake(smallMargin, gutterWidth, bottomMargin, gutterWidth);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment