I have an UIImage that I want write a string onto. Currently I use the following code to place a string onto the image:
+ (UIImage*)writeText:(UIImage*) photo :(CGPoint)point {
NSString *text = @"Hello World!";
UIFont *font = [UIFont fontWithName:@"HelveticaNeue" size:21];
UIGraphicsBeginImageContext(photo.size);
[photo drawInRect:CGRectMake(0,0,photo.size.width,photo.size.height)];
CGRect rect = CGRectMake(point.x, (point.y - 5), photo.size.width, photo.size.height);
[[UIColor whiteColor] set];
NSMutableAttributedString* attString = [[NSMutableAttributedString alloc] initWithString:text];
NSRange range = NSMakeRange(0, [attString length]);
[attString addAttribute:NSFontAttributeName value:font range:range];
[attString addAttribute:NSForegroundColorAttributeName value:[UIColor whiteColor] range:range];
NSShadow* shadow = [[NSShadow alloc] init];
shadow.shadowColor = [UIColor darkGrayColor];
shadow.shadowOffset = CGSizeMake(1.0f, 1.5f);
[attString addAttribute:NSShadowAttributeName value:shadow range:range];
[attString drawInRect:CGRectIntegral(rect)];
UIImage* newPhoto = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newPhoto;
}
How can I extend this code to allow dragging the text across the image? How can I rotate the text with a UIRotationGestureRecognizer? How can I resize the font with UIPinchGestureRecognizer?
I am considering rendering the text as an image and dragging, rotating, and pinching the image. The problem I have with this is I'm afraid it will cause pixilation.