Commit 034e747f authored by Steven杜宇's avatar Steven杜宇

// 方案

parent a9f44649
......@@ -14,19 +14,17 @@ class YHPlanViewController: YHBaseViewController {
override func viewDidLoad() {
super.viewDidLoad()
self.view.backgroundColor = .black
let v = YHPlanScoreView(frame: .zero)
self.view.addSubview(v)
v.snp.makeConstraints { make in
make.width.height.equalTo(248)
make.centerX.equalToSuperview()
make.centerY.equalToSuperview()
make.left.right.equalToSuperview()
make.top.equalTo(300)
make.height.equalTo(442)
}
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
v.updateScores([1.3, 3.5, 2.5, 4.5])
v.chartView.updateScores([3.0, 3.0, 3.0, 3.0])
}
}
......@@ -9,21 +9,56 @@
import UIKit
class YHPlanScoreDrawView: UIView {
let squareWidth = 180.0
var points: [CGPoint] = []
// 定义四个坐标点
var points: [CGPoint] = [] {
var scores: [CGFloat] = [] {
didSet {
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)
self.points = [point1, point2, point3, point4]
setNeedsDisplay() // 坐标变化时触发重绘
if self.pointViews.count == points.count {
for (index, view) in self.pointViews.enumerated() {
view.removeFromSuperview()
view.center = points[index]
// 微调点的位置
var point = self.points[index]
var gap = 1.0
if index == 0 || index == 3 {
gap = 1.0
} else {
gap = -1.0
}
if !isInteger(scores[index]) {
if index % 2 == 0 { // 垂直的两个点
point.y += gap
} else { // 水平的两个点
point.x += gap
}
}
view.center = point
self.addSubview(view)
}
}
}
}
func isInteger(_ value: CGFloat) -> Bool {
return value.truncatingRemainder(dividingBy: 1) == 0
}
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))
......@@ -206,12 +241,7 @@ class YHPlanScoreChart: UIView {
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
self.drawView.scores = scores
careerItemView.scoreLabel.text = "\(scores[0])"
lifeItemView.scoreLabel.text = "\(scores[1])"
......
......@@ -23,6 +23,7 @@ class YHPlanScoreView: UIView {
lable.textColor = UIColor.init(hex: 0x6A7586)
lable.textAlignment = .center
lable.font = UIFont.PFSC_R(ofSize: 13)
lable.text = "您的续签评估等级为"
return lable
}()
......@@ -31,12 +32,87 @@ class YHPlanScoreView: UIView {
lable.textColor = UIColor.mainTextColor
lable.textAlignment = .center
lable.font = UIFont(name: "AlibabaPuHuiTi_3_95_ExtraBold", size: 24)
lable.text = "强"
return lable
}()
func setupUI() {
lazy var statusLineView: UIView = {
let v = UIView()
v.backgroundColor = .init(hex: 0xE9ECF0)
return v
}()
lazy var chartView: YHPlanScoreChart = {
let v = YHPlanScoreChart(frame: .zero)
return v
}()
lazy var descLabel: UILabel = {
let lable = UILabel()
lable.textColor = UIColor.init(hex: 0x6A7586)
lable.textAlignment = .left
lable.font = UIFont.PFSC_R(ofSize: 13)
lable.numberOfLines = 0
lable.text = "您已获得香港居民身份,办理项目为高才计划,根据您得情况综合分析结果如下:这是一段文字描述"
return lable
}()
override init(frame: CGRect) {
super.init(frame: frame)
createUI()
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func createUI() {
backgroundColor = .clear
self.addSubview(whiteContentView)
whiteContentView.addSubview(titleLabel)
whiteContentView.addSubview(statusLineView)
whiteContentView.addSubview(statusLabel)
whiteContentView.addSubview(chartView)
whiteContentView.addSubview(descLabel)
whiteContentView.snp.makeConstraints { make in
make.left.equalTo(16)
make.right.equalTo(-16)
make.top.equalTo(0)
make.bottom.equalTo(-20)
}
titleLabel.snp.makeConstraints { make in
make.height.equalTo(18)
make.top.equalTo(20)
make.centerX.equalToSuperview()
}
statusLineView.snp.makeConstraints { make in
make.width.equalTo(64)
make.height.equalTo(8)
make.bottom.equalTo(statusLabel.snp.bottom).offset(-2)
make.centerX.equalToSuperview()
}
statusLabel.snp.makeConstraints { make in
make.height.equalTo(34)
make.top.equalTo(titleLabel.snp.bottom).offset(8)
make.centerX.equalToSuperview()
}
chartView.snp.makeConstraints { make in
make.top.equalTo(statusLineView.snp.bottom).offset(20)
make.left.right.equalToSuperview()
make.height.equalTo(268)
}
descLabel.snp.makeConstraints { make in
make.left.equalTo(16)
make.right.equalTo(-16)
make.top.equalTo(chartView.snp.bottom).offset(20)
make.bottom.equalTo(-20)
}
}
}
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