1
votes

I want to display CPTAxisLabel intwo lines if the text length is greater than 50 characters. How can i do that? I saw a method to draw a string in a rect. But I don't know how to call this method. If the following method is the solution for this please help me how to call this. Otherwise please provide me otherway.

Thanks in advance -(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

1 Answers

0
votes

No need to reinvent the wheel—CPTTextLayer can do multi-line text. Insert newline characters ('\n') where you want line breaks. CPTTextStyle can control the text alignment (left, center, right).