PQBaseVideoInfoView.swift 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. //
  2. // PQMessageVideoInfoView.swift
  3. // PQSpeed
  4. //
  5. // Created by SanW on 2020/11/12.
  6. // Copyright © 2020 BytesFlow. All rights reserved.
  7. //
  8. import BFCommonKit
  9. import BFMediaKit
  10. import BFUIKit
  11. import UIKit
  12. open class PQBaseVideoInfoView: UIView {
  13. public lazy var imageView: UIImageView = {
  14. let imageView = UIImageView(image: UIImage.moduleImage(named: "msg_default", moduleName: "BFStuckPointKit", isAssets: false))
  15. imageView.addCorner(corner: 4)
  16. imageView.contentMode = .scaleAspectFill
  17. return imageView
  18. }()
  19. public lazy var videoTagView: UIImageView = {
  20. let videoTagView = UIImageView(image: UIImage.moduleImage(named: "msg_video_tag", moduleName: "BFStuckPointKit", isAssets: false))
  21. return videoTagView
  22. }()
  23. public lazy var titleLab: UILabel = {
  24. let titleLab = UILabel()
  25. titleLab.textColor = UIColor.hexColor(hexadecimal: "#CCCCCC")
  26. titleLab.numberOfLines = 3
  27. titleLab.font = UIFont(name: "PingFangSC", size: 13)
  28. return titleLab
  29. }()
  30. override public init(frame: CGRect) {
  31. super.init(frame: frame)
  32. addSubview(imageView)
  33. addSubview(titleLab)
  34. imageView.addSubview(videoTagView)
  35. backgroundColor = UIColor.hexColor(hexadecimal: "#171718")
  36. }
  37. public required init?(coder _: NSCoder) {
  38. fatalError("init(coder:) has not been implemented")
  39. }
  40. open var videoData: PQVideoListModel? {
  41. didSet {
  42. addData()
  43. addLayout()
  44. }
  45. }
  46. open func addData() {
  47. // 这里会crash
  48. let coverImg = (videoData?.videoCoverSnapshotPath != nil && (videoData?.videoCoverSnapshotPath?.count ?? 0) > 0) ? videoData?.videoCoverSnapshotPath ?? "" : (videoData?.coverImg?["coverImgPath"] as? String ?? "")
  49. imageView.setNetImage(url: coverImg, placeholder: UIImage.moduleImage(named: "msg_default", moduleName: "BFStuckPointKit", isAssets: false)!)
  50. titleLab.text = videoData?.title
  51. }
  52. open func addLayout() {
  53. let margin: CGFloat = 12
  54. let imageH: CGFloat = 57
  55. let imageW: CGFloat = imageH * (100.0 / 57.0)
  56. let tagW: CGFloat = 21
  57. let tagH: CGFloat = 23
  58. imageView.snp.makeConstraints { make in
  59. make.left.equalToSuperview().offset(margin)
  60. make.width.equalTo(imageW)
  61. make.height.equalTo(imageH)
  62. make.centerY.equalToSuperview()
  63. }
  64. videoTagView.snp.makeConstraints { make in
  65. make.right.bottom.equalToSuperview().offset(-3)
  66. make.width.equalTo(tagW)
  67. make.height.equalTo(tagH)
  68. }
  69. titleLab.snp.makeConstraints { make in
  70. make.top.equalTo(imageView)
  71. make.left.equalTo(imageView.snp.right).offset(margin)
  72. make.right.equalToSuperview().offset(-margin)
  73. }
  74. }
  75. }