Created
August 29, 2013 16:39
-
-
Save miketihonchik/6380472 to your computer and use it in GitHub Desktop.
draw text over any image (pass additional parameters, so that text is not pixelated)
This file contains 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
- (UIImage *)drawTextOnImage:(NSString *)text :(UIImage *)img { | |
UIGraphicsBeginImageContextWithOptions(img.size, NO, [UIScreen mainScreen].scale); | |
CGRect imageBoundaries = CGRectMake(0,0, img.size.width, img.size.height); | |
[img drawInRect:imageBoundaries]; | |
imageBoundaries.origin.y = (imageBoundaries.size.height - 14) / 2 - 4; | |
imageBoundaries = CGRectIntegral(imageBoundaries); | |
imageBoundaries.size.height = 14; | |
[[UIColor grayColor] set]; | |
[text drawInRect:imageBoundaries withFont:[UIFont boldSystemFontOfSize:14] lineBreakMode:NSLineBreakByTruncatingTail alignment:NSTextAlignmentCenter]; | |
UIImage *theImage=UIGraphicsGetImageFromCurrentImageContext(); | |
UIGraphicsEndImageContext(); | |
return theImage; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I am using this, but whatever I do, the end image is blurred.
Have you every had a similar experience?