Skip to content

Instantly share code, notes, and snippets.

@badeen
Created November 27, 2012 22:31
Show Gist options
  • Save badeen/4157621 to your computer and use it in GitHub Desktop.
Save badeen/4157621 to your computer and use it in GitHub Desktop.
- (void)drawLinesInRect:(CGRect)rect forFont:(UIFont *)font
{
CGFloat maxLineHeight = 30.0f;
CGFloat fontLineHeight = roundf(font.lineHeight);
CGFloat fontBaselineAdjustment = roundf(-font.descender);
CGFloat startY = fmodf(yOffset, fontLineHeight);
CGFloat totalDrawnLines = (int)(floorf(CGRectGetHeight(rect) / fontLineHeight));
for (NSUInteger drawnLine = 0; drawnLine < totalDrawnLines; drawnLine++) {
CGFloat lineY = startY + (drawnLine + 1) * fontLineHeight - fontBaselineAdjustment;
CGRect lineRect = CGRectMake(0.0f,
roundf(lineY),
CGRectGetWidth(rect),
-1.0f);
CGContextFillRect(UIGraphicsGetCurrentContext(), lineRect);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment