【问题标题】:Core Plot: Add text label to padded area around plotAreaFrame核心情节:将文本标签添加到 plotAreaFrame 周围的填充区域
【发布时间】:2014-01-04 00:07:06
【问题描述】:

我正在创建一个条形图,然后在上面添加空格,如下所示....

CPTGraph *graph = self.hostView.hostedGraph;
graph.plotAreaFrame.paddingTop = smallPlotTopOffset; //some number like 25.0

我已经给graph本身添加了paddingTop,然后用titleDisplacement将graph.title移动到了这个空间中。

但是,现在我想在由 plotAreaFrame.paddingTop 创建的空间中,在标题和图形之间添加一个标签。这可能使用 CPTTextLayers 吗?我一直在尝试添加一个图层,但它们似乎受到 plotAreaFrame 的限制(即在填充内)。我想将我的标签在我的 graph.title 下方居中对齐,因此尝试使用 hostView,而不是仅仅将 UILabel 添加到 superview。

【问题讨论】:

    标签: ios cocoa-touch core-plot


    【解决方案1】:

    对于其他感兴趣的人,我按以下方式进行操作......

    CPTLayerAnnotation *ann = [[CPTLayerAnnotation alloc] initWithAnchorLayer:self.hostView.hostedGraph.plotAreaFrame];
    ann.rectAnchor = CPTRectAnchorTop; //to make it the top centre of the plotFrame
    ann.displacement = CGPointMake(0, -20.0); //To move it down, below the title
    
    CPTTextLayer *textLayer = [[CPTTextLayer alloc] initWithText:@"Your Text" style:nil];
    
    ann.contentLayer = textLayer;
    
    [self.hostView.hostedGraph.plotAreaFrame addAnnotation:ann];
    

    我认为这是最好的方法,但如果我可以将其锚定在主标题下方,而不是添加手动位移会更好。

    【讨论】:

      【解决方案2】:

      使用图层注释并将其添加到图表中。

      【讨论】:

        猜你喜欢
        • 2018-05-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多