KeyboardVipTipView.swift 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. //
  2. // KeyboardVipTipView.swift
  3. // AiKeyboard
  4. //
  5. // Created by Destiny on 2025/4/25.
  6. //
  7. import UIKit
  8. import Lottie
  9. class KeyboardVipTipView: UIView {
  10. lazy var bgImageView: UIImageView = {
  11. let imageView = UIImageView()
  12. imageView.image = UIImage(named: "keyboard_bg")
  13. return imageView
  14. }()
  15. lazy var backBtn: UIButton = {
  16. let btn = UIButton()
  17. btn.setImage(UIImage(named: "keyboard_back_btn"), for: .normal)
  18. btn.layer.shadowOffset = CGSize(width: 0, height: 0)
  19. btn.layer.shadowColor = UIColor.hexStringColor(hexString: "#000000", alpha: 0.12).cgColor
  20. btn.layer.shadowRadius = 6.1
  21. btn.addTarget(self, action: #selector(backButtonClickAction), for: .touchUpInside)
  22. return btn
  23. }()
  24. lazy var topImageView: UIImageView = {
  25. let imageView = UIImageView()
  26. imageView.image = UIImage(named: "keyboard_vip_top")
  27. return imageView
  28. }()
  29. lazy var mainView: UIView = {
  30. let view = UIView()
  31. view.backgroundColor = .white
  32. view.layer.cornerRadius = 20
  33. return view
  34. }()
  35. lazy var mainLabel: UILabel = {
  36. let label = UILabel()
  37. label.numberOfLines = 2
  38. label.text = "您的免费提问次数已用完\n可订阅会员解锁无线提问"
  39. label.font = .systemFont(ofSize: 14, weight: .medium)
  40. label.textColor = .hexStringColor(hexString: "#000000", alpha: 0.8)
  41. return label
  42. }()
  43. lazy var unlockBtnAnimation: LottieAnimationView = {
  44. let animate = LottieAnimationView(name: "vip_button")
  45. animate.loopMode = .loop
  46. animate.backgroundColor = .clear
  47. return animate
  48. }()
  49. lazy var unlockLabel: UILabel = {
  50. let name = self.getFontPostScriptName(from: "淘宝买菜体.ttf")
  51. let label = UILabel()
  52. label.text = "¥0.1/天解锁"
  53. label.font = UIFont(name: name ?? "", size: 24)
  54. label.textColor = .white
  55. return label
  56. }()
  57. override init(frame: CGRect) {
  58. super.init(frame: frame)
  59. setUI()
  60. }
  61. required init?(coder: NSCoder) {
  62. fatalError("init(coder:) has not been implemented")
  63. }
  64. func getFontPostScriptName(from fontFile: String) -> String? {
  65. guard let path = Bundle.main.path(forResource: fontFile, ofType: nil) else {
  66. return nil
  67. }
  68. let fontURL = URL(fileURLWithPath: path)
  69. guard let fontDataProvider = CGDataProvider(url: fontURL as CFURL),
  70. let font = CGFont(fontDataProvider) else {
  71. return nil
  72. }
  73. return font.postScriptName as String?
  74. }
  75. }
  76. extension KeyboardVipTipView {
  77. @objc func backButtonClickAction() {
  78. self.removeFromSuperview()
  79. }
  80. }
  81. extension KeyboardVipTipView {
  82. func setUI() {
  83. self.addSubview(bgImageView)
  84. bgImageView.snp.makeConstraints { make in
  85. make.edges.equalToSuperview()
  86. }
  87. self.addSubview(backBtn)
  88. backBtn.snp.makeConstraints { make in
  89. make.size.equalTo(CGSize(width: 32, height: 32))
  90. make.left.equalTo(12)
  91. make.top.equalTo(14)
  92. }
  93. self.addSubview(topImageView)
  94. topImageView.snp.makeConstraints { make in
  95. make.size.equalTo(CGSize(width: 264, height: 98.5))
  96. make.top.equalTo(47)
  97. make.centerX.equalToSuperview()
  98. }
  99. self.addSubview(mainView)
  100. mainView.snp.makeConstraints { make in
  101. make.size.equalTo(CGSize(width: 285, height: 122))
  102. make.centerX.equalToSuperview()
  103. make.top.equalTo(topImageView.snp.bottom).offset(-9)
  104. }
  105. mainView.addSubview(mainLabel)
  106. mainLabel.snp.makeConstraints { make in
  107. make.centerX.equalToSuperview()
  108. make.top.equalTo(21)
  109. }
  110. self.addSubview(unlockBtnAnimation)
  111. unlockBtnAnimation.snp.makeConstraints { make in
  112. make.size.equalTo(CGSize(width: 300, height: 48))
  113. make.centerX.equalToSuperview()
  114. make.top.equalTo(mainView.snp.bottom).offset(-30)
  115. }
  116. unlockBtnAnimation.play()
  117. unlockBtnAnimation.addSubview(unlockLabel)
  118. unlockLabel.snp.makeConstraints { make in
  119. make.center.equalToSuperview()
  120. }
  121. }
  122. }