Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/44.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone iOS-在石英上垂直缩放文本_Iphone_Ios_Ipad_Quartz Graphics - Fatal编程技术网

Iphone iOS-在石英上垂直缩放文本

Iphone iOS-在石英上垂直缩放文本,iphone,ios,ipad,quartz-graphics,Iphone,Ios,Ipad,Quartz Graphics,我正在根据石英背景写一些文字 我有一个500 x 200像素的盒子,我正在里面写一些文字。该框可以有任何纵横比,但文本将始终按原样的字体比例书写。我想要的是垂直缩放字体并保持水平缩放 请看图片。第一个框代表我得到的,第二个框代表我想要的 我就是这样写的 CGRect rect = CGRectMake(0,0,500,200); [myText drawInRect:rect withFont:aFont lineBreakMode:UILineBreakMod

我正在根据石英背景写一些文字

我有一个500 x 200像素的盒子,我正在里面写一些文字。该框可以有任何纵横比,但文本将始终按原样的字体比例书写。我想要的是垂直缩放字体并保持水平缩放

请看图片。第一个框代表我得到的,第二个框代表我想要的

我就是这样写的

CGRect rect = CGRectMake(0,0,500,200);
[myText drawInRect:rect
        withFont:aFont
        lineBreakMode:UILineBreakModeTailTruncation
        alignment:UITextAlignmentCenter];
有没有办法垂直缩放字体

注意:由于这是在PDF上下文中编写的,我不想 将文本渲染到图像上下文并垂直缩放,因为 我不想失去决心


谢谢

我想不出这样做的方法。这些字体本质上只是一组固定的纵横比图示符,因此,即使您能够找到一种方法让iOS以更大的高度渲染,您仍然会丢失分辨率。即使像GIMP这样的图形程序也不允许这种文本呈现。当文本呈现到PDF上下文时会发生什么?它是矢量化的吗?如果是这样,理论上,它可以缩放到任何纵横比而不丢失分辨率。我找到了这个CGContextSetTextMatrix函数。这样做的目的是什么?理论上,这似乎是我想要的,但当我创建一个CGAffineTransformMakeScale(1.0f,1.5f)以查看它是否将文本按Y缩放50%时,没有任何变化……也许它可以与truetype字体一起工作?这些不是矢量的吗?据我所知,所有的字体都是矢量的…您好!请看一下下面的回答,并说明它是否对您有帮助??
  - (void) scaleTextVerticallyWithContext:(CGContextRef)myContext withRect:(CGRect)contextRect
{
    CGFloat w, h;
    w = contextRect.size.width;
    h = contextRect.size.height;

    CGAffineTransform myTextTransform;    
    CGContextSelectFont (myContext, "Helvetica-Bold", h/10, kCGEncodingMacRoman);
    CGContextSetCharacterSpacing (myContext, 10);
    CGContextSetTextDrawingMode (myContext, kCGTextFillStroke); 

    CGContextSetRGBFillColor (myContext, 0, 1, 0, .5);
    CGContextSetRGBStrokeColor (myContext, 0, 0, 1, 1);  

         /*  
          *  CGAffineTransformMakeScale ( CGFloat sx, CGFloat sy );
          *  sx: The factor by which to scale the x-axis of the coordinate system.
          *  sy: The factor by which to scale the y-axis of the coordinate system.  
          */

    myTextTransform = CGAffineTransformMakeScale(1,8);

    CGContextSetTextMatrix (myContext, myTextTransform);
    CGContextShowTextAtPoint (myContext, 40, 0, "Hello There", 9);
}

- (void)drawRect:(CGRect)rect{

    // Drawing code
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGRect viewBounds = self.bounds;
    CGContextTranslateCTM(context, 0, viewBounds.size.height);
    CGContextScaleCTM(context, 1, -1);

    [self scaleTextVerticallyWithContext:context withRect:viewBounds];
}