CGContextShowTextAtPointではなく、drawAtPointで文字列を描画しようとしています。
- (UIImage *)drawonimage:(UIImage *)img {
// myString is a string to draw
// fontName is a string (font name)
// fontSize is the font size (CGfloat)
CGFloat w = img.size.width;
CGFloat h = img.size.height;
UIGraphicsBeginImageContextWithOptions(img.size,NO,1.0f);
CGColorSpaceRef colorSpace0 = CGColorSpaceCreateDeviceRGB();
CGContextRef context0 = CGBitmapContextCreate(NULL,w,h,8,4 * w,colorSpace0,kCGImageAlphaPremultipliedFirst);
CGContextDrawImage(context0,CGRectMake(0,0,w,h),img.CGImage);
CGPoint p0 = CGPointMake(0,0);
[img drawAtPoint:p0];
CGPoint p1 = CGPointMake(0,0);
UIColor *aColor;
aColor = [UIColor colorWithRed:100/255.0 green:120.0/255.0 blue:140.0/255.0 alpha:90/100.0];
CGContextSetFillColorWithColor(UIGraphicsGetCurrentContext(),aColor.CGColor);
[myString drawAtPoint:p1 withFont:[UIFont fontWithName:fontName size:fontSize]];
UIImage *Img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return Img;
}
私が抱えている問題は、文字列が実際に表示される場所です。たとえば、描きたい文字列が「Hello world!」だとします。文字列の左上隅が 0,0 に配置されていません。(写真参照)フォントやフォントサイズなどによって見え方が変わると思います。それで、弦の高さ(幅ではなく)を測定する方法があるのだろうか? または、文字列の左上隅 (矢印) が 0,0 に配置されるようにするにはどうすればよいでしょうか?
ご協力ありがとうございました。