如何在iphone sdk中使用core Plot库将CPT Axis Label换行成两行?

时间:2011-10-24 14:12:06

标签: objective-c ios4 core-plot

如果文本长度大于50个字符,我想在两行中显示CPTAxisLabel。我怎样才能做到这一点?我看到了一个在rect中绘制字符串的方法。但我不知道如何调用这种方法。  如果以下方法是解决方案,请帮助我如何调用它。否则请另外提供给我。

提前致谢 - (void)drawInRect:(CGRect)rect withTextStyle:(CPTTextStyle *)style inContext:(CGContextRef)context {
    if(style.color == nil)return;

CGContextSaveGState(context);
CGColorRef textColor = style.color.cgColor;

CGContextSetStrokeColorWithColor(context, textColor);   
CGContextSetFillColorWithColor(context, textColor);

CPTPushCGContext(context);  

UIFont *theFont = [UIFont fontWithName:style.fontName size:style.fontSize];

[self drawInRect:rect
        withFont:theFont
   lineBreakMode:UILineBreakModeWordWrap
       alignment:(UITextAlignment)style.textAlignment];

CGContextRestoreGState(context);
CPTPopCGContext();

}

1 个答案:

答案 0 :(得分:0)

无需重新发明轮子 - CPTTextLayer可以执行多行文字。在换行符处插入换行符('\ n')。 CPTTextStyle可以控制文本对齐方式(左,中,右)。