Skip to content

Instantly share code, notes, and snippets.

@engmsaleh
Forked from miketihonchik/DrawTextOnImage.m
Last active August 29, 2015 14:06
Show Gist options
  • Save engmsaleh/ba4cf54df2e62950dcc5 to your computer and use it in GitHub Desktop.
Save engmsaleh/ba4cf54df2e62950dcc5 to your computer and use it in GitHub Desktop.
- (UIImage *)drawTextOnImage:(NSString *)text :(UIImage *)img {
UIGraphicsBeginImageContext(img.size);
CGRect imageBoundaries = CGRectMake(0,0, img.size.width, img.size.height);
[img drawInRect:imageBoundaries];
[[UIColor grayColor] set];
[text drawInRect:imageBoundaries withFont:[UIFont boldSystemFontOfSize:15] 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