Commit a9f44649 authored by Steven杜宇's avatar Steven杜宇

// 方案

parent 56c9e815
...@@ -628,6 +628,12 @@ extension YHMyNewViewController { ...@@ -628,6 +628,12 @@ extension YHMyNewViewController {
} }
func clickItem(_ item: PersonalModuleItem) { func clickItem(_ item: PersonalModuleItem) {
do {
let vc = YHPlanViewController()
self.navigationController?.pushViewController(vc)
return
}
if !checkLogin() { if !checkLogin() {
return return
} }
......
...@@ -10,21 +10,23 @@ import UIKit ...@@ -10,21 +10,23 @@ import UIKit
class YHPlanViewController: YHBaseViewController { class YHPlanViewController: YHBaseViewController {
let v = YHPlanScoreChart(frame: .zero)
override func viewDidLoad() { override func viewDidLoad() {
super.viewDidLoad() super.viewDidLoad()
// Do any additional setup after loading the view. self.view.addSubview(v)
v.snp.makeConstraints { make in
make.width.height.equalTo(248)
make.centerX.equalToSuperview()
make.centerY.equalToSuperview()
}
} }
override func viewWillAppear(_ animated: Bool) {
/* super.viewWillAppear(animated)
// MARK: - Navigation v.updateScores([1.3, 3.5, 2.5, 4.5])
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// Get the new view controller using segue.destination.
// Pass the selected object to the new view controller.
} }
*/
} }
...@@ -8,7 +8,55 @@ ...@@ -8,7 +8,55 @@
import UIKit import UIKit
class YHPlanScoreItemView: UIView { class YHPlanScoreDrawView: UIView {
// 定义四个坐标点
var points: [CGPoint] = [] {
didSet {
setNeedsDisplay() // 坐标变化时触发重绘
if self.pointViews.count == points.count {
for (index, view) in self.pointViews.enumerated() {
view.removeFromSuperview()
view.center = points[index]
self.addSubview(view)
}
}
}
}
lazy var pointViews: [YHPlanScorePointView] = {
let v1 = YHPlanScorePointView(frame: CGRect(x: 0, y: 0, width: 8, height: 8))
let v2 = YHPlanScorePointView(frame: CGRect(x: 0, y: 0, width: 8, height: 8))
let v3 = YHPlanScorePointView(frame: CGRect(x: 0, y: 0, width: 8, height: 8))
let v4 = YHPlanScorePointView(frame: CGRect(x: 0, y: 0, width: 8, height: 8))
return [v1, v2, v3, v4]
}()
override func draw(_ rect: CGRect) {
guard points.count == 4 else { return } // 确保有四个点
// 创建一个路径
let path = UIBezierPath()
// 移动到第一个点
path.move(to: points[0])
path.addLine(to: points[1])
path.addLine(to: points[2])
path.addLine(to: points[3])
path.close()
// 设置填充颜色为黑色,透明度50%
UIColor.init(hex: 0xAE6C32).withAlphaComponent(0.1).setFill()
path.fill()
// 设置线条颜色为红色
UIColor.init(hex: 0xAE6C32).setStroke()
path.lineWidth = 1.0
path.stroke()
}
}
class YHPlanScoreItemView: UIView {
lazy var titleLabel: UILabel = { lazy var titleLabel: UILabel = {
let lable = UILabel() let lable = UILabel()
...@@ -52,8 +100,53 @@ class YHPlanScoreItemView: UIView { ...@@ -52,8 +100,53 @@ class YHPlanScoreItemView: UIView {
} }
} }
class YHPlanScorePointView: UIView {
lazy var bigCircleView: UIView = {
let v = UIView()
v.backgroundColor = UIColor.init(hex: 0xAE6C32, alpha: 0.2)
v.layer.cornerRadius = 4.0
return v
}()
lazy var smallCircleView: UIView = {
let v = UIView()
v.backgroundColor = UIColor.init(hex: 0xAE6C32)
v.layer.cornerRadius = 2.0
return v
}()
override init(frame: CGRect) {
super.init(frame: frame)
createUI()
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func createUI() {
self.addSubview(bigCircleView)
self.addSubview(smallCircleView)
bigCircleView.snp.makeConstraints { make in
make.width.height.equalTo(8)
make.centerX.equalToSuperview()
make.centerY.equalToSuperview()
}
smallCircleView.snp.makeConstraints { make in
make.width.height.equalTo(4)
make.centerX.equalToSuperview()
make.centerY.equalToSuperview()
}
}
}
class YHPlanScoreChart: UIView { class YHPlanScoreChart: UIView {
let squareWidth = 180.0
lazy var squareImgV: UIImageView = { lazy var squareImgV: UIImageView = {
let v = UIImageView() let v = UIImageView()
v.image = UIImage(named: "plan_score_square") v.image = UIImage(named: "plan_score_square")
...@@ -66,6 +159,12 @@ class YHPlanScoreChart: UIView { ...@@ -66,6 +159,12 @@ class YHPlanScoreChart: UIView {
return v return v
}() }()
lazy var drawView: YHPlanScoreDrawView = {
let v = YHPlanScoreDrawView(frame: .zero)
v.backgroundColor = .clear
return v
}()
lazy var careerItemView: YHPlanScoreItemView = { lazy var careerItemView: YHPlanScoreItemView = {
let v = YHPlanScoreItemView(frame: .zero) let v = YHPlanScoreItemView(frame: .zero)
v.titleLabel.text = "事业" v.titleLabel.text = "事业"
...@@ -103,6 +202,23 @@ class YHPlanScoreChart: UIView { ...@@ -103,6 +202,23 @@ class YHPlanScoreChart: UIView {
fatalError("init(coder:) has not been implemented") fatalError("init(coder:) has not been implemented")
} }
func updateScores(_ scores: [CGFloat]) {
guard scores.count == 4 else { return } // 确保有四个点
let point1 = CGPoint(x: squareWidth/2.0, y: (1.0 - scores[0]/5.0)*squareWidth/2.0)
let point2 = CGPoint(x: (1.0 + scores[1]/5.0)*squareWidth/2.0, y: squareWidth/2.0)
let point3 = CGPoint(x: squareWidth/2.0, y: (1.0 + scores[2]/5.0)*squareWidth/2.0)
let point4 = CGPoint(x: (1.0 - scores[3]/5.0)*squareWidth/2.0, y: squareWidth/2.0)
let points = [point1, point2, point3, point4]
self.drawView.points = points
careerItemView.scoreLabel.text = "\(scores[0])"
lifeItemView.scoreLabel.text = "\(scores[1])"
investItemView.scoreLabel.text = "\(scores[2])"
stayItemView.scoreLabel.text = "\(scores[3])"
}
func createUI() { func createUI() {
self.addSubview(circleBgImgV) self.addSubview(circleBgImgV)
self.addSubview(squareImgV) self.addSubview(squareImgV)
...@@ -110,9 +226,10 @@ class YHPlanScoreChart: UIView { ...@@ -110,9 +226,10 @@ class YHPlanScoreChart: UIView {
self.addSubview(lifeItemView) self.addSubview(lifeItemView)
self.addSubview(investItemView) self.addSubview(investItemView)
self.addSubview(stayItemView) self.addSubview(stayItemView)
squareImgV.addSubview(drawView)
squareImgV.snp.makeConstraints { make in squareImgV.snp.makeConstraints { make in
make.height.width.equalTo(182) make.height.width.equalTo(squareWidth)
make.centerX.equalToSuperview() make.centerX.equalToSuperview()
make.centerY.equalToSuperview() make.centerY.equalToSuperview()
} }
...@@ -123,6 +240,10 @@ class YHPlanScoreChart: UIView { ...@@ -123,6 +240,10 @@ class YHPlanScoreChart: UIView {
make.centerY.equalToSuperview() make.centerY.equalToSuperview()
} }
drawView.snp.makeConstraints { make in
make.edges.equalToSuperview()
}
careerItemView.snp.makeConstraints { make in careerItemView.snp.makeConstraints { make in
make.centerX.equalToSuperview() make.centerX.equalToSuperview()
make.bottom.equalTo(squareImgV.snp.top).offset(-5) make.bottom.equalTo(squareImgV.snp.top).offset(-5)
...@@ -139,7 +260,14 @@ class YHPlanScoreChart: UIView { ...@@ -139,7 +260,14 @@ class YHPlanScoreChart: UIView {
investItemView.snp.makeConstraints { make in investItemView.snp.makeConstraints { make in
make.centerX.equalToSuperview() make.centerX.equalToSuperview()
make.bottom.equalTo(squareImgV.snp.top).offset(-5) make.top.equalTo(squareImgV.snp.bottom).offset(5)
make.height.equalTo(38)
make.width.equalTo(40)
}
stayItemView.snp.makeConstraints { make in
make.centerY.equalToSuperview()
make.right.equalTo(squareImgV.snp.left).offset(-5)
make.height.equalTo(38) make.height.equalTo(38)
make.width.equalTo(40) make.width.equalTo(40)
} }
......
...@@ -34,8 +34,6 @@ class YHPlanScoreView: UIView { ...@@ -34,8 +34,6 @@ class YHPlanScoreView: UIView {
return lable return lable
}() }()
func setupUI() { func setupUI() {
backgroundColor = .clear backgroundColor = .clear
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
"scale" : "1x" "scale" : "1x"
}, },
{ {
"filename" : "中间图形.png", "filename" : "中间图形@2x.png",
"idiom" : "universal", "idiom" : "universal",
"scale" : "2x" "scale" : "2x"
}, },
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment