如何将图像添加到 Core Plot CPTBarPlot 图层?
是否可以将 UIImageView 添加到 CPTBarPlot 层(来自 Core Plot 框架)?我已尝试以下操作,但它仅在图表的一角创建图像,我希望它位于栏上:
NSString *bundlePath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"wrong.png"];
UIImage *image = [[UIImage alloc] initWithContentsOfFile:bundlePath];
UIImageView *incorrect = [[UIImageView alloc] initWithFrame:CGRectMake(plot.bounds.origin.x,plot.bounds.origin.y,14,14)];
[incorrect setImage:image];
[plot addSublayer:incorrect.layer];
[image release];
[incorrect release];
Is it possible to add a UIImageView to a CPTBarPlot layer (from the Core Plot framework)? I have tried the following, but it only creates the image in the corner of the graph and I want it to be on the bar:
NSString *bundlePath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"wrong.png"];
UIImage *image = [[UIImage alloc] initWithContentsOfFile:bundlePath];
UIImageView *incorrect = [[UIImageView alloc] initWithFrame:CGRectMake(plot.bounds.origin.x,plot.bounds.origin.y,14,14)];
[incorrect setImage:image];
[plot addSublayer:incorrect.layer];
[image release];
[incorrect release];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您可以通过使用图像创建 CPTFill 并使用条形图的委托/数据源返回条形图的填充来实现此目的。
如果您不希望图像实际位于栏中,而是位于其旁边或顶部,最好创建一个 CTPlotSpaceAnnotation,并将其附加到绘图区域。
I think you could do this by creating a CPTFill with the image, and using the delegate/data source of the bar plot to return the fill for the bar.
If you don't want the image actually in the bar, but next to or on top of it, best to create a CPTPlotSpaceAnnotation, and attach that to the plot area.