FolderHeaderView.swift 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. //
  2. // FolderHeaderView.swift
  3. // O2Platform
  4. //
  5. // Created by 刘振兴 on 16/9/14.
  6. // Copyright © 2016年 zoneland. All rights reserved.
  7. //
  8. import UIKit
  9. import CocoaLumberjack
  10. private let buttonWidth = 60
  11. private let buttonHeight = 30
  12. private let labelWidth = 15
  13. private let labelHeight = 30
  14. protocol FolderHeaderViewDelegate {
  15. func headerClickSelected(currentFile f:OOFile,folderQueue fQueue:[OOFile])
  16. }
  17. class FolderHeaderView: UIView {
  18. var folderQueue:[OOFile]?
  19. var rootFile = OOFile()
  20. var delegate:FolderHeaderViewDelegate?
  21. override init(frame: CGRect) {
  22. super.init(frame: frame)
  23. //let button = createButton(file:rootFile,index:-1)
  24. let button = genernateButton(rootFile,-1)
  25. button.tag = 1001
  26. addSubview(button)
  27. let count = folderQueue?.count
  28. for i in 0 ..< (count ?? 0) {
  29. let f = self.folderQueue![i]
  30. let sp = genernateSymbol()
  31. addSubview(sp)
  32. let btn = genernateButton(f,i)
  33. btn.tag = 2000+i
  34. addSubview(btn)
  35. }
  36. }
  37. required init?(coder aDecoder: NSCoder) {
  38. fatalError("init(coder:) has not been implemented")
  39. }
  40. override func layoutSubviews() {
  41. //根目录button
  42. var x=5,y=5
  43. super.layoutSubviews()
  44. for view in self.subviews {
  45. if view.isKind(of: UIButton.self){
  46. if view.tag == 1001 {
  47. view.frame = CGRect(x: CGFloat(x), y: CGFloat(y), width: CGFloat(buttonWidth), height: CGFloat(buttonHeight))
  48. }else{
  49. x += labelWidth
  50. view.frame = CGRect(x: CGFloat(x), y: CGFloat(y), width: CGFloat(buttonWidth), height: CGFloat(buttonHeight))
  51. }
  52. }else if view.isKind(of: UILabel.self){
  53. x += buttonWidth
  54. view.frame = CGRect(x: CGFloat(x), y: CGFloat(y), width: CGFloat(labelWidth), height: CGFloat(labelHeight))
  55. }
  56. }
  57. }
  58. func genernateButton(_ file:OOFile,_ index:Int) -> UIButton {
  59. let button = UIButton(type: .custom)
  60. button.setTitle(file.name, for: .normal)
  61. button.setTitleColor(UIColor.gray, for: .normal)
  62. button.layer.borderWidth = 1
  63. button.layer.borderColor = base_color.cgColor
  64. button.layer.masksToBounds = true
  65. button.layer.cornerRadius = 12
  66. button.tag = index
  67. button.bounds = CGRect(x: 0, y: 0, width: CGFloat(buttonWidth), height: CGFloat(buttonHeight))
  68. button.titleLabel?.font = UIFont.systemFont(ofSize: 12)
  69. return button
  70. }
  71. func genernateSymbol() -> UILabel {
  72. let label = UILabel()
  73. label.text = "->"
  74. label.textColor = base_color
  75. label.font = UIFont.systemFont(ofSize: 12)
  76. label.bounds = CGRect(x: 0, y: 0, width: labelWidth, height: labelHeight)
  77. return label
  78. }
  79. }