Commit 55f4e53f08b2b386c95a6e01e90a8e950383c640

Authored by Cao yang
1 parent 79394633
Exists in parentassistant

点击折线图添加数字显示

ParentAssistant/ParentAssistant.xcworkspace/xcuserdata/caoyang.xcuserdatad/UserInterfaceState.xcuserstate
No preview for this file type
ParentAssistant/ParentAssistant/Classes/controllers/report/View/LineChartView.swift
... ... @@ -29,9 +29,11 @@ class LineChartView: UIView {
29 29 private let xMoveLayer = CAShapeLayer()
30 30 //纵坐标Lab数组
31 31 private var yMoveLaArr = Array<UILabel>()
32   -
33   -
34   -
  32 + //折线图数据数组
  33 + private var dateArr = Array<Array<Int>>()
  34 + //显示的数字
  35 + var yLabArray = Array<UILabel>()
  36 +
35 37 override init(frame: CGRect) {
36 38 super.init(frame: frame)
37 39 print("frame==\(frame)")
... ... @@ -68,7 +70,7 @@ class LineChartView: UIView {
68 70 private func drawX() {
69 71 let xWidth = (screenWidth-20)/CGFloat(yCount)
70 72 for index in 0..<xCount {
71   - let nameBtn = UIButton.init(frame: CGRect.init(x: xWidth+CGFloat(index)*xWidth, y: self.bounds.height-70, width: 40, height: 20))
  73 + let nameBtn = UIButton.init(frame: CGRect.init(x: xWidth+CGFloat(index)*xWidth, y: self.bounds.height-70, width: 40, height: 25))
72 74 nameBtn.setTitle(xLabArr[index], for: UIControlState.normal)
73 75 nameBtn.setTitleColor(UIColorWithRGB(R: 119, G: 119, B: 119), for: UIControlState.normal)
74 76 nameBtn.titleLabel!.textAlignment = .center
... ... @@ -97,14 +99,18 @@ class LineChartView: UIView {
97 99 self.layer.addSublayer(drawLayer)
98 100 drawLayer.setNeedsDisplay()
99 101  
  102 + dateArr.append(point)
  103 +
100 104 }
101   - //MARK: - 画竖线
  105 + //MARK: - 点击横坐标
102 106 @objc func touchXAction(tap:UIButton){
103 107  
104 108 let index = tap.tag
105   -
  109 +
  110 +
106 111 if btnTouch != index {
107 112  
  113 + //竖虚线
108 114 lineLayer.strokeColor = UIColorWithRGB(R: 92, G: 145, B: 230).cgColor
109 115 lineLayer.lineWidth = 1
110 116 let arr = [5,5]
... ... @@ -112,6 +118,7 @@ class LineChartView: UIView {
112 118 lineLayer.lineDashPattern = arr as [NSNumber]
113 119 self.layer.addSublayer(lineLayer)
114 120  
  121 + //X轴下划线
115 122 let movePath = CGMutablePath()
116 123 movePath.move(to: CGPoint.init(x: xCenterArr[index], y: yCenterArr[0]))
117 124 movePath.addLine(to: CGPoint.init(x: xCenterArr[index], y: 10+5*(self.bounds.height-60)/CGFloat(yCount)))
... ... @@ -121,17 +128,40 @@ class LineChartView: UIView {
121 128 xMoveLayer.lineWidth = 2
122 129 self.layer.addSublayer(xMoveLayer)
123 130 let movePath2 = CGMutablePath()
124   - movePath2.move(to: CGPoint.init(x: xCenterArr[index]-15, y: self.bounds.height-50))
125   - movePath2.addLine(to: CGPoint.init(x: xCenterArr[index]+15, y: self.bounds.height-50))
  131 + movePath2.move(to: CGPoint.init(x: xCenterArr[index]-15, y: self.bounds.height-45))
  132 + movePath2.addLine(to: CGPoint.init(x: xCenterArr[index]+15, y: self.bounds.height-45))
126 133 xMoveLayer.path = movePath2
127 134  
  135 + if yLabArray.count == dateArr.count {
  136 + for label in yLabArray {
  137 + label.removeFromSuperview()
  138 + }
  139 + }
  140 + yLabArray.removeAll()
  141 + //数字显示
  142 + for i in 0..<dateArr.count {
  143 + let arr = dateArr[i]
  144 + //y坐标数值
  145 + let y = arr[index]
  146 + let yLab = yMoveLaArr[GPA-y]
  147 + var rect = yLab.frame
  148 + rect.origin.x = xCenterArr[index]+10
  149 +
  150 + let newLab = UILabel()
  151 + newLab.text = yLab.text
  152 + newLab.textColor = yLab.textColor
  153 + newLab.font = yLab.font
  154 + newLab.frame = rect
  155 + self.addSubview(newLab)
  156 + yLabArray.append(newLab)
  157 + }
  158 + }else{
  159 + print(yLabArray)
128 160 }
129 161 btnTouch = index
130 162  
131 163  
132 164 }
133   - //MARK: - 特定横坐标颜色,下划线
134   -
135 165 //转换y坐标
136 166 func swichPoint(arr:Array<Int>)->Array<Int>{
137 167 var array = Array<Int>()
... ...