2016-04-28 9 views
1

CPTAnnotationでNSAttributedStringを改行して使用しようとしています。 以下のコードを使用すると、「firstString ...」だけが表示されます。 \ n記号を削除すると、両方の文字列が正しく表示されます(適切なサイズと色)が、1行に表示されます。CPTTextLayer - 複数行NSAttributedString

注釈で使用されるCPTTextLayerで、labelOnlineLine = 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

注釈はどこに表示されていますか? 2行目がプロット領域の端で切り取られる可能性はありますか? Core Plotは、ラベル全体が表示されるように自動的にレイアウトを調整しません。 –

+0

私はスクリーンショットを追加しました。間違いなくプロット領域で切り取られます。 – izik461

+0

使用しているCore Plotのバージョンは?これは、シミュレータとデバイスの両方で発生するのでしょうか? iOSのどのバージョンでテストしていますか? –

答えて

0

おかげで、私はそれを解決しました。 フォント:アンテナに問題がありました。他のフォントを使用すると、注釈が正しく表示されます。