我想要在TableView中绘制一个具有5行的里程碑,我在单元格中添加了一个标签“O”,此处行高为44,并试图连接这些圆点 Something像这样 O ------ O ------ O ------ O ----- O垂直,但我无法弄清楚这里缺少什么,请参考以下代码在桌面视图中使用BezierPath创建时间轴视图
class StopslistTableViewCell:UITableViewCell{
@IBOutlet weak var milestoneLbl: UILabel!
override func draw(_ rect: CGRect) {
let scrrenX = UIScreen.main.bounds.width - 30
let frametosuperview = milestoneLbl.convert(milestoneLbl!.frame, to: self.superview)
print("dotframetosuperview",frametosuperview)
//print(CGPoint(x: scrrenX, y: previousposY + rect.size.height))
//frametosuperview.origin.y > 40 ? frametosuperview.origin.y - 20 : frametosuperview.origin.y
let path = UIBezierPath()
path.move(to: CGPoint(x: scrrenX, y:frametosuperview.origin.y < 30 ? frametosuperview.origin.y : frametosuperview.origin.y - frametosuperview.height))
print("move to point--->",frametosuperview.origin.y < 30 ? frametosuperview.origin.y : frametosuperview.origin.y - frametosuperview.height)
path.addLine(to: CGPoint(x: scrrenX, y: frametosuperview.origin.y < 30 ? frametosuperview.height + 24 : (frametosuperview.origin.y + 24)))
print("add line to point--->",CGPoint(x: scrrenX, y: frametosuperview.origin.y < 30 ? frametosuperview.height + 24 : (frametosuperview.origin.y + 24)))
path.lineWidth = 5
UIColor.red.setStroke()
path.stroke()
setNeedsDisplay()
}
调试输出
dotframetosuperview (560.0, 20.0, 20.0, 20.0)
move to point---> 20.0
add line to point---> (290.0, 44.0)
dotframetosuperview (560.0, 64.0, 20.0, 20.0)
move to point---> 44.0
add line to point---> (290.0, 88.0)
dotframetosuperview (560.0, 108.0, 20.0, 20.0)
move to point---> 88.0
add line to point---> (290.0, 132.0)
dotframetosuperview (560.0, 152.0, 20.0, 20.0)
move to point---> 132.0
add line to point---> (290.0, 176.0)
dotframetosuperview (560.0, 196.0, 20.0, 20.0)
move to point---> 176.0
add line to point---> (290.0, 220.0)
我需要像这样
我无法得到想要的结果,我在这里错过了什么..?
请张贴更多的信息。有什么问题“我无法获得理想的结果”?预期的输出,实际的输出... – shallowThought
如果你想要更多的信息,复制tableviewcell中的代码,在xib中获取一个tableview,拖拽一个单元格,在其上放置一个标签,将标签附加到里程碑并运行。 – iSwift