KeyboardMenuView.swift 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. //
  2. // KeyboardMenuView.swift
  3. // AiKeyboard
  4. //
  5. // Created by Destiny on 2025/4/28.
  6. //
  7. import UIKit
  8. protocol KeyboardMenuViewDelegate: NSObjectProtocol {
  9. func menuBackBtnClickAction()
  10. func vipBtnClickAction()
  11. func diyBtnClickAction()
  12. func marketBtnClickAction()
  13. }
  14. class KeyboardMenuView: UIView {
  15. struct UX {
  16. static let btnWidth = (KeyboardConst.kb_kScreenW - 36.0) / 2.0
  17. static let btnHeight = 74.0
  18. }
  19. weak var delegate: KeyboardMenuViewDelegate?
  20. lazy var backBtn: UIButton = {
  21. let btn = UIButton()
  22. btn.setImage(UIImage(named: "keyboard_back_btn"), for: .normal)
  23. btn.layer.shadowOffset = CGSize(width: 0, height: 0)
  24. btn.layer.shadowColor = UIColor.hexStringColor(hexString: "#000000", alpha: 0.12).cgColor
  25. btn.layer.shadowRadius = 6.1
  26. btn.addTarget(self, action: #selector(backBtnClickAction), for: .touchUpInside)
  27. return btn
  28. }()
  29. lazy var diyCharacterBtn: UIButton = {
  30. let btn = UIButton(frame: CGRect(x: 0, y: 0, width: UX.btnWidth, height: UX.btnHeight))
  31. btn.backgroundColor = .white
  32. btn.layer.cornerRadius = 14
  33. btn.setTitle("定制人设", for: .normal)
  34. btn.setTitleColor(.hexStringColor(hexString: "#000000", alpha: 0.8), for: .normal)
  35. btn.titleLabel?.font = .systemFont(ofSize: 13, weight: .medium)
  36. btn.titleLabel?.textAlignment = .center
  37. btn.setImage(UIImage(named: "keyboard_menu_diy"), for: .normal)
  38. btn.setImageTitleLayout(.imgTop, spacing: 8)
  39. btn.addTarget(self, action: #selector(diyBtnClickAction), for: .touchUpInside)
  40. return btn
  41. }()
  42. lazy var marketBtn: UIButton = {
  43. let btn = UIButton(frame: CGRect(x: 0, y: 0, width: UX.btnWidth, height: UX.btnHeight))
  44. btn.backgroundColor = .white
  45. btn.layer.cornerRadius = 14
  46. btn.setTitle("人设市场", for: .normal)
  47. btn.setTitleColor(.hexStringColor(hexString: "#000000", alpha: 0.8), for: .normal)
  48. btn.titleLabel?.font = .systemFont(ofSize: 13, weight: .medium)
  49. btn.titleLabel?.textAlignment = .center
  50. btn.setImage(UIImage(named: "keyboard_menu_market"), for: .normal)
  51. btn.setImageTitleLayout(.imgTop, spacing: 8)
  52. btn.addTarget(self, action: #selector(marketBtnClickAction), for: .touchUpInside)
  53. return btn
  54. }()
  55. lazy var vipBtn: UIButton = {
  56. let btn = UIButton(frame: CGRect(x: 0, y: 0, width: UX.btnWidth, height: UX.btnHeight))
  57. btn.backgroundColor = .white
  58. btn.layer.cornerRadius = 14
  59. btn.setTitle("解锁会员", for: .normal)
  60. btn.setTitleColor(.hexStringColor(hexString: "#000000", alpha: 0.8), for: .normal)
  61. btn.titleLabel?.font = .systemFont(ofSize: 13, weight: .medium)
  62. btn.titleLabel?.textAlignment = .center
  63. btn.setImage(UIImage(named: "keyboard_menu_vip"), for: .normal)
  64. btn.setImageTitleLayout(.imgTop, spacing: 8)
  65. btn.addTarget(self, action: #selector(vipBtnClickAction), for: .touchUpInside)
  66. return btn
  67. }()
  68. override init(frame: CGRect) {
  69. super.init(frame: frame)
  70. initUI()
  71. }
  72. required init?(coder: NSCoder) {
  73. fatalError("init(coder:) has not been implemented")
  74. }
  75. }
  76. extension KeyboardMenuView {
  77. @objc func backBtnClickAction() {
  78. delegate?.menuBackBtnClickAction()
  79. }
  80. @objc func vipBtnClickAction() {
  81. delegate?.vipBtnClickAction()
  82. }
  83. @objc func marketBtnClickAction() {
  84. delegate?.marketBtnClickAction()
  85. }
  86. @objc func diyBtnClickAction() {
  87. delegate?.diyBtnClickAction()
  88. }
  89. }
  90. extension KeyboardMenuView {
  91. func initUI() {
  92. self.addSubview(backBtn)
  93. backBtn.snp.makeConstraints { make in
  94. make.size.equalTo(CGSize(width: 32, height: 32))
  95. make.left.equalTo(12)
  96. make.top.equalTo(16)
  97. }
  98. self.addSubview(diyCharacterBtn)
  99. diyCharacterBtn.snp.makeConstraints { make in
  100. make.size.equalTo(CGSize(width: UX.btnWidth, height: UX.btnHeight))
  101. make.top.equalTo(60)
  102. make.left.equalTo(12)
  103. }
  104. self.addSubview(marketBtn)
  105. marketBtn.snp.makeConstraints { make in
  106. make.size.equalTo(CGSize(width: UX.btnWidth, height: UX.btnHeight))
  107. make.top.equalTo(60)
  108. make.right.equalTo(-12)
  109. }
  110. self.addSubview(vipBtn)
  111. vipBtn.snp.makeConstraints { make in
  112. make.size.equalTo(CGSize(width: UX.btnWidth, height: UX.btnHeight))
  113. make.top.equalTo(diyCharacterBtn.snp.bottom).offset(12)
  114. make.left.equalTo(12)
  115. }
  116. }
  117. }