Blame view

HDFwear/Setting/VIew/TitleView.swift 3.86 KB
f2cf74c7   yangbin   1.0.20(4)
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
  //
  //  SearchTitleView.swift
  //  zc
  //
  //  Created by wyp on 2020/11/9.
  //  Copyright © 2020 wyp. All rights reserved.
  //
  
  import UIKit
  
  protocol TitleViewDelegate: NSObjectProtocol {
      
      func didClickButton(sender: UIButton)
      
      
  }
  
  
  class TitleView: UIView {
      weak var delegate: TitleViewDelegate?
      
      private lazy var userButton: UIButton = {
          let button = UIButton()
          button.addTarget(self, action: #selector(clickButton(sender:)), for: .touchUpInside)
  //        button.setTitle("用户", for: .normal)
          button.tag = 1
          button.setTitleColor(UIColor.rgbColorFromHex(0x999999), for: .normal)
          button.titleLabel?.font = RegularFont(14)
          return button
      }()
      
      private lazy var newsButton: UIButton = {
          let button = UIButton()
          button.tag = 0
          button.addTarget(self, action: #selector(clickButton(sender:)), for: .touchUpInside)
  //        button.setTitle("内容", for: .normal)
          button.setTitleColor(UIColor.rgbColorFromHex(0xEE6C4D), for: .normal)
          button.titleLabel?.font = RegularFont(16)
          return button
      }()
      
      
      init(frame: CGRect, titles: [String] = ["内容", "用户"]) {
          super.init(frame: frame)
  //        backgroundColor = .red
          setupSubViews(titles: titles)
      }
      
  
      @objc func clickButton(sender: UIButton) {
          delegate?.didClickButton(sender: sender)
          
          if sender.tag == 0 {
              newsButton.titleLabel?.font = RegularFont(16)
              newsButton.setTitleColor(UIColor.rgbColorFromHex(0xEE6C4D), for: .normal)
              userButton.setTitleColor(UIColor.rgbColorFromHex(0x999999), for: .normal)
              userButton.titleLabel?.font = RegularFont(14)
              
          } else if sender.tag == 1 {
              userButton.titleLabel?.font = RegularFont(16)
              userButton.setTitleColor(UIColor.rgbColorFromHex(0xEE6C4D), for: .normal)
              newsButton.setTitleColor(UIColor.rgbColorFromHex(0x999999), for: .normal)
              newsButton.titleLabel?.font = RegularFont(14)
          }
      }
      
      func refreshButton(index: Int) {
          if index == 0 {
              newsButton.titleLabel?.font = RegularFont(16)
              newsButton.setTitleColor(UIColor.rgbColorFromHex(0xEE6C4D), for: .normal)
              userButton.setTitleColor(UIColor.rgbColorFromHex(0x999999), for: .normal)
              userButton.titleLabel?.font = RegularFont(14)
              
          } else if index == 1 {
              userButton.titleLabel?.font = RegularFont(16)
              userButton.setTitleColor(UIColor.rgbColorFromHex(0xEE6C4D), for: .normal)
              newsButton.setTitleColor(UIColor.rgbColorFromHex(0x999999), for: .normal)
              newsButton.titleLabel?.font = RegularFont(14)
          }
      }
      
      
      func setupSubViews(titles: [String]) {
  //        addSubview(sliderScrollView)
  //        addSubview(pageBottomLineView)
          userButton.setTitle(titles[1], for: .normal)
          newsButton.setTitle(titles[0], for: .normal)
          addSubview(newsButton)
          addSubview(userButton)
          newsButton.snp.makeConstraints { (make) in
              make.width.equalTo(50)
              make.height.equalTo(30)
              make.centerY.equalToSuperview()
              make.centerX.equalToSuperview().multipliedBy(0.67)
          }
          userButton.snp.makeConstraints { (make) in
              make.width.equalTo(50)
              make.height.equalTo(30)
              make.centerY.equalToSuperview()
              make.centerX.equalToSuperview().multipliedBy(1.33)
          }
          
          
          
      }
  
      
      
      
      required init?(coder: NSCoder) {
          fatalError("init(coder:) has not been implemented")
      }
      /*
      // Only override draw() if you perform custom drawing.
      // An empty implementation adversely affects performance during animation.
      override func draw(_ rect: CGRect) {
          // Drawing code
      }
      */
  
  }