我试图在CPTAnnotation中使用带有换行符的NSAttributedString。 使用下面的代码时,仅显示“firstString ...”。 删除\ n符号时,两个字符串都正确显示(大小和颜色正确),但在一行中。
是否可以在注释中使用的CPTTextLayer上使用类似于label的numberOfLines = 0(启用换行符)的内容?
NSMutableAttributedString* finalString = [firstAttrStr mutableCopy];
NSMutableAttributedString *newLineAttrStr = [[NSMutableAttributedString alloc]initWithString:@"\n"];
[finalLabel appendAttributedString:newLineAttrStr];
[finalLabel appendAttributedString:secondAttrStr];
//additional setup in here
CPTTextLayer *textLayer = [[CPTTextLayer alloc] initWithAttributedText:finalLabel];
textLayer.fill = [CPTFill fillWithColor:[CPTColor whiteColor]];
textLayer.cornerRadius = 3.0;
textLayer.paddingLeft = 0.5;
textLayer.paddingTop = 0.5;
textLayer.paddingRight = 0.5;
textLayer.paddingBottom = 0.5;
textLayer.hidden = NO;
//add shadow
textLayer.masksToBounds = NO;
textLayer.shadowOffset = CGSizeMake(0, 0);
textLayer.shadowRadius = 5;
textLayer.shadowOpacity = 0.3;
_highlightAnnotation = [[CPTPlotSpaceAnnotation alloc] initWithPlotSpace:plotSpace anchorPlotPoint:@[middlePoint, yAnnotationPosition]];
[_highLightPlot addAnnotation:_highlightAnnotation];
CPTTextLayer *textLayer = [[CPTTextLayer alloc] initWithAttributedText:finalString];
_highlightAnnotation.contentLayer = textLayer;
看起来像是:
答案 0 :(得分:0)
感谢Eric的建议,我解决了它。 问题出在字体:天线上。使用其他字体时,正确显示注释。