2013-07-01 28 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