Created
November 27, 2012 22:31
-
-
Save badeen/4157621 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (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