PQBaseVideoInfoView.swift 2.8 KB

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