在objective-c iPhone上的图像上写文字,模拟器的字体大小与iPhone本身不同 [英] Write text on image in objective-c iPhone, Font size of simulator different from on iPhone itself

查看:107
本文介绍了在objective-c iPhone上的图像上写文字,模拟器的字体大小与iPhone本身不同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些非常奇怪的事情,我正在为图像添加标题,一切在模拟器上运行正常但在设备本身上字体非常小...

I'm having something really weird going, I'm adding caption to an image and everything works fine on simulator but on the device itself the font is really small...

使用此代码时遇到问题:

I have a problem when using this code :

-(UIImage*) drawTextOnPic:(NSString*) bottomText
         inImage:(UIImage*)  image
{

UIFont *font = [UIFont boldSystemFontOfSize:48];
UIGraphicsBeginImageContext(image.size);
[image drawInRect:CGRectMake(0,0,image.size.width,image.size.height)];

CGRect = CGRectMake(10.0f,10.0f,image.size.width-20.0f, image.size.height);

CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetShadow(context, CGSizeMake(2.5f, 2.5f), 5.0f);


[[UIColor whiteColor] set];
[bottomText drawInRect:CGRectIntegral(rect) withFont:font lineBreakMode:UILineBreakModeClip alignment:UITextAlignmentCenter];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

return newImage;
}

有人知道为什么它只能在我预期的模拟器上工作吗?顺便说一句,我正在使用适用于iOS6的SDK,它可以用于那里吗?
这是视网膜显示器吗?如何解决?

Does someone know why it works only on simulator as I expected? BTW, I'm using the SDK for iOS6, Can it be something there? Is it something with the retina display? How to fix that?

推荐答案

我选择默认字体大小(在我的情况下是48)然后根据图像尺寸检查对于一些ref大小(在我的情况下为640x480),我通过sqrtf(区域(a)/区域(ref))来做,然后将此结果乘以字体大小。
这是它对我有用的唯一方式。

I choose the default font size (on my case it's 48) and then checked the image size according to some ref size (in my case 640x480), I did that by sqrtf(area(a)/area(ref)) then multiply this result on font size. That's the only way it works for me.

希望这对别人有用......

Hope that would help others...

这篇关于在objective-c iPhone上的图像上写文字,模拟器的字体大小与iPhone本身不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆