我的图表气球正在从屏幕the answer by @usr的边界切割 那我怎么能改变图像的箭头 是否可以更改标记箭头(箭头到左侧/右侧)作为图像显示?
此气球标记由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文件
编写答案 0 :(得分:1)
气球标记只是您如何使用它的一个示例。 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: size.height
您只需创建ChartMarker
子类并通过覆盖draw(context context: CGContext, point: CGPoint)
进行自定义
如果您不想使用图像,那么您必须使用CoreGraphics,因为您已经看到了绘制您喜欢的形状。不过,您有责任决定如何绘制形状。
关于在屏幕边缘切割,这是另一个问题,因为你的形状太大而无法在中心显示。无论是改变大小还是改变你的形状方向等等都可以解决它,这取决于你。