I'm trying to implement draw stroke text with color and border on UIImage but I can't get the solution.
I have used this THLabel for stroke and border of text and it works fine but only when I copy that code into draw image so at that time it's working for me.
Please see the screen shot for the same. Any suggestions?
Draw Text on UIImage Method :
- (UIImage *) drawText:(NSString*)text
inImage:(UIImage*)image
atPoint:(NSString *)location{
CGFloat fontSize = image.size.width*3/30.0;
NSString *fontName = @"Arial";
int w = image.size.width;
int h = image.size.height;
UIFont *font=[UIFont fontWithName:fontName size:fontSize];
UIGraphicsBeginImageContext(image.size);
[image drawInRect:CGRectMake(0,0,image.size.width,image.size.height)];
int textFrameY = 25;
int textFrameX = 5;
CGSize aSize = [text sizeWithFont:font];
CGRect rect = CGRectMake(textFrameX,textFrameY, 80, 30);
CGSize lSize = [location sizeWithFont:font];
CGRect rect1 = CGRectMake(image.size.width-lSize.width-fontSize-textFrameX, h-(fontSize*3)-textFrameY, w, h);
[[UIColor blackColor] set];
CGContextFillRect(UIGraphicsGetCurrentContext(), rect1);
CGContextFillRect(UIGraphicsGetCurrentContext(), rect);
[[UIColor whiteColor] set];
[text drawInRect:CGRectIntegral(rect) withFont:font];
[location drawInRect:CGRectIntegral(rect1) withFont:font];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;}
THLabel code for stroke color and border for text method:
// Demonstrate stroke.
self.label3.strokeColor = kStrokeColor;
self.label3.strokeSize = kStrokeSize;
