gpt4 book ai didi

ios - 如何更改 ios-charts 中的气球标记图像?

转载 作者:行者123 更新时间:2023-11-29 01:19:49 24 4
gpt4 key购买 nike

“我的图表”气球被从屏幕边界剪切 Like this那么我如何更改图像的箭头 Like this是否可以更改图像中显示的标记箭头(向左侧/右侧的箭头)?

这个气球标记是由CGContext绘制的,其代码如下

CGContextSaveGState(context)
CGContextSetFillColorWithColor(context, color?.CGColor)
CGContextBeginPath(context)
CGContextMoveToPoint(context,
rect.origin.x,
rect.origin.y)
CGContextAddLineToPoint(context,
rect.origin.x + rect.size.width,
rect.origin.y)
CGContextAddLineToPoint(context,
rect.origin.x + rect.size.width,
rect.origin.y + rect.size.height - arrowSize.height)
CGContextAddLineToPoint(context,
rect.origin.x + (rect.size.width + arrowSize.width) / 2.0,
rect.origin.y + rect.size.height - arrowSize.height)
CGContextAddLineToPoint(context,
rect.origin.x + rect.size.width / 2.0,
rect.origin.y + rect.size.height)
CGContextAddLineToPoint(context,
rect.origin.x + (rect.size.width - arrowSize.width) / 2.0,
rect.origin.y + rect.size.height - arrowSize.height)
CGContextAddLineToPoint(context,
rect.origin.x,
rect.origin.y + rect.size.height - arrowSize.height)
CGContextAddLineToPoint(context,
rect.origin.x,
rect.origin.y)
CGContextFillPath(context)

这段代码写在balloon-marker.swift文件中

最佳答案

气球标记只是您如何使用它的一个例子。 ChartMarker 类有一些属性,其中有 image 属性。您可以直接使用它来显示您的任何图像。

你需要考虑的是位置和大小。您有责任决定位置和大小,因为默认实现是:

/// Draws the ChartMarker on the given position on the given context
public func draw(context context: CGContext, point: CGPoint)
{
let offset = self.offsetForDrawingAtPos(point)
let size = self.size

let rect = CGRect(x: point.x + offset.x, y: point.y + offset.y, width: size.width, height: size.height)

UIGraphicsPushContext(context)
image!.drawInRect(rect)
UIGraphicsPopContext()
}

你看到它只是在 x: point.x + offset.x, y: point.y + offset.y 处绘制图像,width: size.width, height:大小.高度

您可以简单地创建 ChartMarker 的子类,并通过覆盖 draw(context context: CGContext, point: CGPoint) 进行自定义

如果你不想使用图像,那么你必须像你看到的那样使用 CoreGraphics 来绘制你喜欢的形状。尽管如此,您仍有责任决定如何绘制形状。

关于在屏幕边缘被切割,这是另一个问题,因为你的形状太大而无法显示在中心。要么改变大小,要么改变你的形状方向等等来解决它,由你决定。

关于ios - 如何更改 ios-charts 中的气球标记图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34752721/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com