FolderTreeTableViewCell.swift 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. //
  2. // FolderTreeTableViewCell.swift
  3. // O2Platform
  4. //
  5. // Created by FancyLou on 2021/12/15.
  6. // Copyright © 2021 zoneland. All rights reserved.
  7. //
  8. import UIKit
  9. import CocoaLumberjack
  10. class FolderTreeTableViewCell: UITableViewCell {
  11. var folderNameLabel: UILabel!
  12. var folder: MindFolder?
  13. let offset:CGFloat = 10
  14. override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
  15. super.init(style: style, reuseIdentifier: reuseIdentifier)
  16. // Initialization code
  17. DDLogDebug("Initialization cell。。。。。。")
  18. self.folderNameLabel = UILabel()
  19. self.folderNameLabel.textColor = .black
  20. self.contentView.addSubview(self.folderNameLabel)
  21. }
  22. required init?(coder: NSCoder) {
  23. super.init(coder: coder)
  24. }
  25. override func awakeFromNib() {
  26. super.awakeFromNib()
  27. }
  28. override func setSelected(_ selected: Bool, animated: Bool) {
  29. super.setSelected(selected, animated: animated)
  30. }
  31. override func layoutSubviews() {
  32. super.layoutSubviews()
  33. let width = self.contentView.frame.size.width
  34. let height = self.contentView.frame.size.height
  35. if folder != nil {
  36. let left = offset * CGFloat(folder?.level ?? 1)
  37. let labelWidth = width - offset - left
  38. let labelHeigth = height - (offset * 2)
  39. self.folderNameLabel.frame = CGRect(x: left, y: offset, width: labelWidth, height: labelHeigth)
  40. if folder?.selected == true {
  41. self.folderNameLabel.textColor = base_color
  42. } else {
  43. self.folderNameLabel.textColor = .black
  44. }
  45. } else {
  46. DDLogError("没有数据。。。。。。。。。。")
  47. }
  48. }
  49. func setFolderModel(folder: MindFolder) {
  50. self.folder = folder
  51. self.folderNameLabel.text = self.folder?.name
  52. }
  53. }