【问题标题】:Core-Plot: How to center custom image plot symbolCore-Plot:如何使自定义图像绘图符号居中
【发布时间】:2013-02-03 18:38:12
【问题描述】:

我正在使用自定义图像符号,如 Showing images on Scattering Graph as plot symbols in Core plot iOS 中所述。有关在 CPTPlot 中定位数据标签的信息,另请参阅 Positioning label on CPTBarPlot (Core-Plot)

但是,我没有看到我需要的来自 CPTScatterPlot.labelOffset 的行为。正值增加图像底部和点之间的距离,而负值增加图像顶部和点之间的距离。我需要将图像集中在该点上。看截图:

  • 正 labelOffset 值:
  • 负标签偏移值:

我的解决方案很老套,需要我在CustomImageForScatterPlotdrawInContext 方法中修改图像帧。关于如何让labelOffset 工作的任何想法?

【问题讨论】:

    标签: ios objective-c image plot core-plot


    【解决方案1】:

    这种行为对于数据标签是正确的。您想使用绘图符号。

    -(CPTPlotSymbol *)symbolForScatterPlot:(CPTScatterPlot *)plot
                               recordIndex:(NSUInteger)index
    {
        CPTPlotSymbol *symbol = nil;
    
        if ( /* use symbol for this index? */ ) {
            symbol = [CPTPlotSymbol ellipsePlotSymbol];
            symbol.fill = [CPTFill fillWithImage:/* symbol image */];
            symbol.size = CGSizeMake(width, height);
        }
    
        return symbol;
    }
    

    如果您希望每个点都有一个符号,请设置 plotSymbol 属性,而不是实现此数据源方法。

    【讨论】:

    • 谢谢,你说得对,我之前使用的是dataLabelForPlot。仅供参考,上面代码示例中的符号图像可以使用以下方式引用 PNG 资源:[CPTImage imageForPNGFile:[[NSBundle mainBundle] pathForResource:@"icon_volume" ofType:@"png"]]
    • 使用资产目录时除外:Pstackoverflow.com/questions/20485453/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-27
    • 2011-01-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多