5 행이있는 TableView에서 이정표를 그리기 위해 셀에 "O"라는 레이블을 추가했습니다. 행 높이가 44이고이 점들을 연결하려고합니다. Something like this O ------ O ------ O ------ O ----- O 세로로,하지만 여기에 무엇이 빠졌는지 알아낼 수 없으므로 다음 코드를 참조하십시오.Tableview에서 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)
내가이
같은 뭔가가 필요원하는 결과를 얻을 수 없습니다. 여기에 뭔가 빠졌습니까? 당신은 UILabel
.Instead이 원하고 점선 패턴으로 라인을 만들 만들 필요가없는
더 많은 정보를 게시하시기 바랍니다. "나는 원하는 결과를 얻을 수 없다"는 문제는 무엇입니까? 예상 출력, 실제 출력 ... – shallowThought
자세한 정보가 필요하면 tableviewcell에서 코드를 복사하고 xib에서 tableview를 얻은 다음 셀을 드래그하고 레이블을 붙여서 마일스톤에 레이블을 붙여 실행하십시오. – iSwift