1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- //
- // IHSubsectionView.swift
- // Inhealth
- //
- // Created by weclouds on 2020/1/16.
- // Copyright © 2020 weclouds. All rights reserved.
- //
- import UIKit
- class IHSubsectionView: NSObject {
-
- static let share = IHSubsectionView()
-
- private var goodView:UIView?
- private var normalView:UIView?
- private var poorView :UIView?
- func showLevel(good:Int,normal:Int,poor:Int,InView view:UIView) {
-
- if goodView != nil {
- goodView?.removeFromSuperview()
- }
- if normalView != nil {
- normalView?.removeFromSuperview()
- }
-
- if poorView != nil {
- normalView?.removeFromSuperview()
- }
- goodView = UIView()
-
- view.addSubview(goodView!)
-
- normalView = UIView()
-
- view.addSubview(normalView!)
-
- poorView = UIView()
-
- view.addSubview(poorView!)
- let total = good + normal + poor
- let goodx = 0
- let goodWidth = view.bounds.size.width * CGFloat(good) / CGFloat(total)
- let normalx = Int(goodWidth)
- let normalWidth = view.bounds.size.width * CGFloat(normal) / CGFloat(total)
- let poorx = Int(goodWidth) + Int(normalWidth)
- let poorWidth = Int(view.bounds.size.width) * poor / total
- goodView?.frame = CGRect(x: goodx, y: 0, width: Int(goodWidth), height: 4)
- normalView?.frame = CGRect(x: normalx, y: 0, width: Int(normalWidth), height: 4)
- poorView?.frame = CGRect(x: poorx, y: 0, width: poorWidth, height: 4)
- // #05CFAB
- goodView?.backgroundColor = UIColor(hexString: "#573F95")
- normalView?.backgroundColor = UIColor(hexString: "#573F95")
- poorView?.backgroundColor = UIColor(hexString: "#FF0C4D")
- }
- }
|