I am drawing Timeline view. I am using UITableView
when I update the new data the circle layer drawn on bottom of previous layer.
This is how it looks when loading new data
Here is my custom cell code:
override func draw(_ rect: CGRect) {
if let anchor = anchorView() {
anchor.layer.zPosition = 3
let iconImageView = anchor as! UIImageView
iconImageView.image = iconImageView.image!.withRenderingMode(UIImageRenderingMode.alwaysTemplate)
iconImageView.tintColor = UIColor.white
let centreRelativeToTableView = anchor.superview!.convert(anchor.center, to: self)
// print("Anchor x origin : \(anchor.frame.size.origin.x)")
timelinePoint.position = CGPoint(x: centreRelativeToTableView.x , y: centreRelativeToTableView.y/2)
timeline.start = CGPoint(x: centreRelativeToTableView.x , y: 0)
timeline.middle = CGPoint(x: timeline.start.x, y: anchor.frame.origin.y)
timeline.end = CGPoint(x: timeline.start.x, y: self.bounds.size.height)
timeline.draw(view: self.contentView)
let circlePath = UIBezierPath(arcCenter: CGPoint(x: anchor.center.x,y: anchor.center.y ), radius: CGFloat(20), startAngle: CGFloat(0), endAngle:CGFloat(M_PI * 2), clockwise: true)
let shapeLayer = CAShapeLayer()
shapeLayer.path = circlePath.cgPath
//change the fill color
shapeLayer.fillColor = UIColor.randomFlat.cgColor
// shapeLayer.fillColor = UIColor.clear.cgColor
//you can change the stroke color
shapeLayer.strokeColor = UIColor.white.cgColor
//you can change the line width
shapeLayer.lineWidth = 0
anchor.alpha = 1
//Set Anchor Z position
anchor.layer.zPosition = 2
shapeLayer.zPosition = 1
anchor.superview?.layer.insertSublayer(shapeLayer, at: 0 )
// anchor.tintColor = UIColor.white
// Setting icon to layer
/* let imageLayer = CALayer()
imageLayer.contents = iconImageView.image
imageLayer.frame = anchor.frame
anchor.layer.addSublayer(imageLayer)*/
// timelinePoint.draw(view: self.contentView)
} else {
print("this should not happen")
}
}
How could I solve this problem
Update: As user atulkhatri points out, it won't work if you don't add: