LNJoinUsAvatarExamplePanel.swift 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. //
  2. // LNJoinUsAvatarExamplePanel.swift
  3. // Gami
  4. //
  5. // Created by OneeChan on 2026/1/20.
  6. //
  7. import Foundation
  8. import UIKit
  9. import SnapKit
  10. class LNJoinUsAvatarExamplePanel: LNPopupView {
  11. override init(frame: CGRect) {
  12. super.init(frame: frame)
  13. setupViews()
  14. }
  15. required init?(coder: NSCoder) {
  16. fatalError("init(coder:) has not been implemented")
  17. }
  18. }
  19. extension LNJoinUsAvatarExamplePanel {
  20. private func setupViews() {
  21. let header = buildHeader()
  22. container.addSubview(header)
  23. header.snp.makeConstraints { make in
  24. make.horizontalEdges.equalToSuperview()
  25. make.top.equalToSuperview()
  26. }
  27. let goodExample = buildGoodExample()
  28. container.addSubview(goodExample)
  29. goodExample.snp.makeConstraints { make in
  30. make.centerX.equalToSuperview()
  31. make.top.equalTo(header.snp.bottom).offset(3)
  32. make.leading.greaterThanOrEqualToSuperview().offset(16)
  33. }
  34. let errExample = buildErr()
  35. container.addSubview(errExample)
  36. errExample.snp.makeConstraints { make in
  37. make.horizontalEdges.equalToSuperview().inset(16)
  38. make.top.equalTo(goodExample.snp.bottom).offset(20)
  39. make.bottom.equalToSuperview().offset(commonBottomInset)
  40. }
  41. }
  42. private func buildHeader() -> UIView {
  43. let container = UIView()
  44. container.snp.makeConstraints { make in
  45. make.height.equalTo(50)
  46. }
  47. let titleLabel = UILabel()
  48. titleLabel.font = .heading_h3
  49. titleLabel.textColor = .text_5
  50. titleLabel.text = .init(key: "B00047")
  51. container.addSubview(titleLabel)
  52. titleLabel.snp.makeConstraints { make in
  53. make.center.equalToSuperview()
  54. }
  55. let closeButton = UIButton()
  56. closeButton.setImage(.init(systemName: "xmark")?.withRenderingMode(.alwaysTemplate), for: .normal)
  57. closeButton.tintColor = .text_2
  58. closeButton.addAction(UIAction(handler: { [weak self] _ in
  59. guard let self else { return }
  60. dismiss()
  61. }), for: .touchUpInside)
  62. container.addSubview(closeButton)
  63. closeButton.snp.makeConstraints { make in
  64. make.centerY.equalToSuperview()
  65. make.trailing.equalToSuperview().offset(-12)
  66. make.width.height.equalTo(24)
  67. }
  68. return container
  69. }
  70. private func buildGoodExample() -> UIView {
  71. let container = UIView()
  72. let avatar = UIImageView()
  73. avatar.image = .icAvatarExampleCorrect
  74. avatar.layer.cornerRadius = 12
  75. avatar.clipsToBounds = true
  76. container.addSubview(avatar)
  77. avatar.snp.makeConstraints { make in
  78. make.leading.top.equalToSuperview()
  79. make.width.height.equalTo(100)
  80. }
  81. let checkIc = UIImageView()
  82. checkIc.image = .icCheck26
  83. container.addSubview(checkIc)
  84. checkIc.snp.makeConstraints { make in
  85. make.trailing.equalTo(avatar).offset(2)
  86. make.bottom.equalTo(avatar).offset(2)
  87. make.bottom.equalToSuperview()
  88. }
  89. let stackView = UIStackView()
  90. stackView.axis = .vertical
  91. stackView.spacing = 9
  92. container.addSubview(stackView)
  93. stackView.snp.makeConstraints { make in
  94. make.leading.equalTo(avatar.snp.trailing).offset(18)
  95. make.trailing.equalToSuperview()
  96. make.centerY.equalToSuperview()
  97. }
  98. let text1 = buildExampleText(.init(key: "B00037"))
  99. stackView.addArrangedSubview(text1)
  100. let text2 = buildExampleText(.init(key: "B00048"))
  101. stackView.addArrangedSubview(text2)
  102. let text3 = buildExampleText(.init(key: "B00049"))
  103. stackView.addArrangedSubview(text3)
  104. return container
  105. }
  106. private func buildExampleText(_ text: String) -> UIView {
  107. let container = UIView()
  108. let dot = UIView()
  109. dot.backgroundColor = .primary_3
  110. dot.layer.cornerRadius = 3
  111. container.addSubview(dot)
  112. dot.snp.makeConstraints { make in
  113. make.leading.equalToSuperview()
  114. make.top.equalToSuperview().offset(5)
  115. make.width.height.equalTo(6)
  116. }
  117. let titleLabel = UILabel()
  118. titleLabel.font = .body_m
  119. titleLabel.textColor = .text_5
  120. titleLabel.text = text
  121. titleLabel.numberOfLines = 0
  122. container.addSubview(titleLabel)
  123. titleLabel.snp.makeConstraints { make in
  124. make.verticalEdges.equalToSuperview()
  125. make.trailing.equalToSuperview()
  126. make.leading.equalTo(dot.snp.trailing).offset(7)
  127. }
  128. return container
  129. }
  130. private func buildErr() -> UIView {
  131. let container = UIStackView()
  132. container.axis = .vertical
  133. container.spacing = 12
  134. let line1 = UIStackView()
  135. line1.spacing = 13
  136. line1.distribution = .fillEqually
  137. line1.alignment = .top
  138. line1.addArrangedSubview(buildErrExample(.icAvatarExample1, text: .init(key: "B00050")))
  139. line1.addArrangedSubview(buildErrExample(.icAvatarExample2, text: .init(key: "B00051")))
  140. line1.addArrangedSubview(buildErrExample(.icAvatarExample3, text: .init(key: "B00052")))
  141. line1.addArrangedSubview(buildErrExample(.icAvatarExample4, text: .init(key: "B00053")))
  142. container.addArrangedSubview(line1)
  143. let line2 = UIStackView()
  144. line2.spacing = 13
  145. line2.distribution = .fillEqually
  146. line2.alignment = .top
  147. line2.addArrangedSubview(buildErrExample(.icAvatarExample5, text: .init(key: "B00054")))
  148. line2.addArrangedSubview(buildErrExample(.icAvatarExample6, text: .init(key: "B00055")))
  149. line2.addArrangedSubview(buildErrExample(.icAvatarExample7, text: .init(key: "B00056")))
  150. line2.addArrangedSubview(buildErrExample(.icAvatarExample8, text: .init(key: "B00057")))
  151. container.addArrangedSubview(line2)
  152. return container
  153. }
  154. private func buildErrExample(_ icon: UIImage, text: String) -> UIView {
  155. let container = UIView()
  156. let avatar = UIImageView()
  157. avatar.image = icon
  158. container.addSubview(avatar)
  159. avatar.snp.makeConstraints { make in
  160. make.horizontalEdges.equalToSuperview()
  161. make.top.equalToSuperview()
  162. make.height.equalTo(avatar.snp.width)
  163. }
  164. let xmark = UIImageView()
  165. xmark.image = .icXMark
  166. container.addSubview(xmark)
  167. xmark.snp.makeConstraints { make in
  168. make.centerX.equalToSuperview()
  169. make.centerY.equalTo(avatar.snp.bottom)
  170. }
  171. let titleLabel = UILabel()
  172. titleLabel.font = .body_xs
  173. titleLabel.textColor = .text_5
  174. titleLabel.text = text
  175. titleLabel.textAlignment = .center
  176. titleLabel.numberOfLines = 2
  177. container.addSubview(titleLabel)
  178. titleLabel.snp.makeConstraints { make in
  179. make.horizontalEdges.equalToSuperview()
  180. make.top.equalTo(xmark.snp.bottom)
  181. make.bottom.equalToSuperview()
  182. }
  183. return container
  184. }
  185. }