FileCell.swift 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. //
  2. // FileCell.swift
  3. // JChat
  4. //
  5. // Created by 邓永豪 on 2017/8/28.
  6. // Copyright © 2017年 HXHG. All rights reserved.
  7. //
  8. import UIKit
  9. class File {
  10. var fileIcon: UIImage
  11. var fileName: String
  12. var fileSize: String
  13. var summary: String
  14. init(_ fileIcon: UIImage, _ fileName: String, _ fileSize: String, _ summary: String) {
  15. self.fileName = fileName
  16. self.fileIcon = fileIcon
  17. self.fileSize = fileSize
  18. self.summary = summary
  19. }
  20. }
  21. class FileCell: JCTableViewCell {
  22. var isEditMode: Bool {
  23. get {
  24. return !selectView.isHidden
  25. }
  26. set {
  27. selectView.isHidden = !newValue
  28. contentView.removeConstraint(selectImageWidthConstraint)
  29. if newValue {
  30. selectImageWidthConstraint = _JCLayoutConstraintMake(selectView, .width, .equal, nil, .notAnAttribute, 21)
  31. } else {
  32. selectImageWidthConstraint = _JCLayoutConstraintMake(selectView, .width, .equal, nil, .notAnAttribute, 0)
  33. }
  34. contentView.addConstraint(selectImageWidthConstraint)
  35. }
  36. }
  37. var isSelectImage: Bool {
  38. get {
  39. return isSelect
  40. }
  41. set {
  42. if newValue {
  43. selectView.image = UIImage.loadImage("com_icon_file_select")
  44. } else {
  45. selectView.image = UIImage.loadImage("com_icon_file_unselect")
  46. }
  47. isSelect = newValue
  48. }
  49. }
  50. required init?(coder aDecoder: NSCoder) {
  51. super.init(coder: aDecoder)
  52. _init()
  53. }
  54. override func awakeFromNib() {
  55. super.awakeFromNib()
  56. _init()
  57. }
  58. func bindData(_ file: File) {
  59. fileIcon.image = file.fileIcon
  60. fileName.text = file.fileName
  61. fileSize.text = file.fileSize
  62. summary.text = file.summary
  63. }
  64. private var selectImageWidthConstraint: NSLayoutConstraint!
  65. private lazy var selectView: UIImageView = UIImageView()
  66. private var isSelect = false
  67. private lazy var fileIcon: UIImageView = UIImageView()
  68. private lazy var fileName: UILabel = {
  69. let fileName = UILabel()
  70. fileName.textColor = UIColor(netHex: 0x2C2C2C)
  71. fileName.font = UIFont.systemFont(ofSize: 15)
  72. return fileName
  73. }()
  74. private lazy var fileSize: UILabel = {
  75. let fileSize = UILabel()
  76. fileSize.textColor = UIColor(netHex: 0x2C2C2C)
  77. fileSize.font = UIFont.systemFont(ofSize: 12)
  78. return fileSize
  79. }()
  80. private lazy var summary: UILabel = {
  81. let summary = UILabel()
  82. summary.textColor = UIColor(netHex: 0x999999)
  83. summary.font = UIFont.systemFont(ofSize: 12)
  84. return summary
  85. }()
  86. private func _init() {
  87. selectView.image = UIImage.loadImage("com_icon_file_unselect")
  88. contentView.addSubview(fileIcon)
  89. contentView.addSubview(fileName)
  90. contentView.addSubview(fileSize)
  91. contentView.addSubview(summary)
  92. contentView.addSubview(selectView)
  93. selectImageWidthConstraint = _JCLayoutConstraintMake(selectView, .width, .equal, nil, .notAnAttribute, 0)
  94. contentView.addConstraint(_JCLayoutConstraintMake(selectView, .left, .equal, contentView, .left, 17.5))
  95. contentView.addConstraint(_JCLayoutConstraintMake(selectView, .centerY, .equal, contentView, .centerY))
  96. contentView.addConstraint(selectImageWidthConstraint)
  97. contentView.addConstraint(_JCLayoutConstraintMake(selectView, .height, .equal, nil, .notAnAttribute, 21))
  98. contentView.addConstraint(_JCLayoutConstraintMake(fileIcon, .left, .equal, selectView, .right, 17.5))
  99. contentView.addConstraint(_JCLayoutConstraintMake(fileIcon, .centerY, .equal, contentView, .centerY))
  100. contentView.addConstraint(_JCLayoutConstraintMake(fileIcon, .width, .equal, nil, .notAnAttribute, 50))
  101. contentView.addConstraint(_JCLayoutConstraintMake(fileIcon, .height, .equal, nil, .notAnAttribute, 50))
  102. contentView.addConstraint(_JCLayoutConstraintMake(fileName, .left, .equal, fileIcon, .right, 12.5))
  103. contentView.addConstraint(_JCLayoutConstraintMake(fileName, .top, .equal, contentView, .top, 14.5))
  104. contentView.addConstraint(_JCLayoutConstraintMake(fileName, .right, .equal, contentView, .right, -17.5))
  105. contentView.addConstraint(_JCLayoutConstraintMake(fileName, .height, .equal, nil, .notAnAttribute, 21))
  106. contentView.addConstraint(_JCLayoutConstraintMake(fileSize, .right, .equal, fileName, .right))
  107. contentView.addConstraint(_JCLayoutConstraintMake(fileSize, .left, .equal, fileName, .left))
  108. contentView.addConstraint(_JCLayoutConstraintMake(fileSize, .top, .equal, fileName, .bottom))
  109. contentView.addConstraint(_JCLayoutConstraintMake(fileSize, .height, .equal, nil, .notAnAttribute, 16.5))
  110. contentView.addConstraint(_JCLayoutConstraintMake(summary, .left, .equal, fileSize, .left))
  111. contentView.addConstraint(_JCLayoutConstraintMake(summary, .right, .equal, fileSize, .right))
  112. contentView.addConstraint(_JCLayoutConstraintMake(summary, .top, .equal, fileSize, .bottom))
  113. contentView.addConstraint(_JCLayoutConstraintMake(summary, .height, .equal, fileSize, .height))
  114. }
  115. }