2016-04-28 85 views
1

我想在CPTAnnotation中用換行符使用NSAttributedString。 使用下面的代碼時,只顯示「firstString ...」。 刪除\ n符號時,兩個字符串都會正確顯示(尺寸和顏色正確),但只能顯示一行。CPTTextLayer - 多行NSAttributedString

是否可以在註釋中使用的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; 

它看起來像:

enter image description here enter image description here

+0

註釋顯示在哪裏?第二行是否可能被繪圖區邊緣剪切? Core Plot不會自動調整佈局以確保整個標籤可見。 –

+0

我已添加屏幕截圖。這絕對不是由地塊面積裁剪。 – izik461

+0

你使用的是什麼版本的Core Plot?這是否發生在模擬器和設備上,或者只是其中之一?你正在測試哪個版本的iOS? –

回答

0

感謝埃裏克的建議,我解決了這個問題。 問題出在字體上:天線。使用其他字體時,註釋顯示正確。