LNRoomWelcomeMessageCell.swift 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. //
  2. // LNRoomWelcomeMessageCell.swift
  3. // Gami
  4. //
  5. // Created by OneeChan on 2026/3/22.
  6. //
  7. import Foundation
  8. import UIKit
  9. import SnapKit
  10. class LNRoomWelcomeMessageCell: UITableViewCell {
  11. private let contentLabel = UILabel()
  12. private var curItem: LNRoomWelcomeMessageItem?
  13. override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
  14. super.init(style: style, reuseIdentifier: reuseIdentifier)
  15. setupViews()
  16. }
  17. func update(_ message: LNRoomWelcomeMessageItem) {
  18. let text = String(key: "A00371", message.nickname)
  19. let attr = NSMutableAttributedString(string: text)
  20. let range = (text as NSString).range(of: message.nickname)
  21. attr.addAttributes([
  22. .foregroundColor: UIColor.text_7,
  23. .font: UIFont.heading_h5
  24. ], range: range)
  25. contentLabel.attributedText = attr
  26. curItem = message
  27. }
  28. required init?(coder: NSCoder) {
  29. fatalError("init(coder:) has not been implemented")
  30. }
  31. }
  32. extension LNRoomWelcomeMessageCell {
  33. private func setupViews() {
  34. backgroundColor = .clear
  35. let container = UIView()
  36. container.backgroundColor = .fill.withAlphaComponent(0.12)
  37. container.layer.cornerRadius = 12
  38. container.onTap { [weak self] in
  39. guard let self else { return }
  40. guard let curItem else { return }
  41. let panel = LNRoomProfileCardPanel()
  42. panel.load(curItem.userNo)
  43. panel.popup(self)
  44. }
  45. contentView.addSubview(container)
  46. container.snp.makeConstraints { make in
  47. make.verticalEdges.equalToSuperview().inset(8)
  48. make.leading.equalToSuperview()
  49. make.trailing.lessThanOrEqualToSuperview()
  50. }
  51. contentLabel.text = " "
  52. contentLabel.font = .heading_h5
  53. contentLabel.textColor = .text_1
  54. contentLabel.numberOfLines = 0
  55. container.addSubview(contentLabel)
  56. contentLabel.snp.makeConstraints { make in
  57. make.horizontalEdges.equalToSuperview().inset(10)
  58. make.verticalEdges.equalToSuperview().inset(8)
  59. }
  60. }
  61. }