2013-07-01 29 views
1

我创建pdf文件。我需要绘制旋转文字。在当前时间我有这个PDF文件IOS创建带有旋转文本的PDF文件

enter image description here

我的代码绘制文本

............ 

CGContextTranslateCTM(context, 0, frameRect.origin.y*2); 
CGContextScaleCTM(context, 1.0, -1.0); 
// Draw the frame. 
CTFrameDraw(frame, context); 


// Add these two lines to reverse the earlier transformation. 
CGContextScaleCTM(context, 1.0, -1.0); 
CGContextTranslateCTM(context, 0, (-1)*frameRect.origin.y*2); 

我知道,我必须用CGContextRotateCTM(CGContextRef c, GFloat angle),但我不好理解转型,我不能做的我需要。

回答

0

下面将文本添加从页面顶部的旋转-90度到指定的上下文在Y偏移:

+(void)addRotatedLabel:(CGContextRef)context atYOffset:(CGFloat)yOffset{ 

    // -90 degrees 
    CGFloat rotation = -M_PI/2.f; 
    CGContextRotateCTM(context, rotation); 

    NSString *label = [NSString stringWithFormat:@"%@", @"some text"]; 
    CGSize maxSize = CGSizeMake(300, 12); 
    UIFont *font = [UIFont systemFontOfSize:7.5f]; 
    CGSize textSize = [label sizeWithFont:font constrainedToSize:maxSize lineBreakMode:NSLineBreakByClipping]; 
    CGRect titleRect = CGRectMake(-yOffset, 32.f - textSize.height + 3.f, textSize.width, textSize.height); 

    [[UIColor blackColor] setFill]; 
    [label drawInRect:titleRect withFont:font]; 

    CGContextRotateCTM(context, -rotation); 
} 

它可以很容易地修改以处理其他的旋转,字体大小,通过在NSString等。

+0

谢谢。它帮助我 – Pavel