Blame view

Twear/Basic/View/CustomProgress.swift 1.33 KB
75d24c15   yangbin   123
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
  //
  //  CustomProgress.swift
  //  Twear
  //
  //  Created by yangbin on 2021/12/21.
  //
  
  import UIKit
  
  class CustomProgress: UIView {
  
      @IBOutlet weak var trackViewWidthLayout: NSLayoutConstraint!
      @IBOutlet weak var trackView: UIView!
      @IBOutlet weak var label: UILabel!
      @IBOutlet weak var backView: UIView!
      
      @IBInspectable
      private var cornerRadius: CGFloat = 0 {
          didSet {
              layer.cornerRadius = cornerRadius
              layer.masksToBounds = cornerRadius > 0
          }
      }
      
      var value: Int = 0 {
          didSet {
              refreshUI()
          }
      }
      
      override init(frame: CGRect) {
          super.init(frame: frame)
          initFromNib()
  
      }
      
      
      required init?(coder: NSCoder) {
          super.init(coder: coder)
          initFromNib()
  
      }
      override class func awakeFromNib() {
          super.awakeFromNib()
         
      }
      
      private func initFromNib() {
          if let view = UINib(nibName: "CustomProgress", bundle: Bundle(for: type(of: self))).instantiate(withOwner: self, options: nil).first as? UIView {
              view.frame = bounds
              self.addSubview(view)
          }
      }
      
      override func layoutSubviews() {
          refreshUI()
      }
      
      private func refreshUI() {
          trackViewWidthLayout.constant = self.frame.width * CGFloat(value)/100
      }
      
  }