项目作者: thierryH91200

项目描述 :
NSOutlineView and badge
高级语言: Swift
项目地址: git://github.com/thierryH91200/THSideBar.git
创建时间: 2017-10-01T16:35:17Z
项目社区:https://github.com/thierryH91200/THSideBar

开源协议:Apache License 2.0

下载




Mac

SideBarDemo

NSOutlineView and badge

Alt text

THSideBar

  1. THSideBar framework written in Swift for OS X

Stargazers over time

Usage

look at example

Initialize the THSideBar

  1. var sideBarViewController : THSideBarViewController?

Add THSideBar to the view hierarchy

  1. self.sideBarViewController = THSideBarViewController()
  2. addSubview(subView: (sideBarViewController?.view)!, toView: sourceView)
  3. sideBarViewController?.delegate = self
  4. sideBarViewController?.allowDragAndDrop = false/true
  5. sideBarViewController?.saveSection = false/true
  6. setUpLayoutConstraints(item: sideBarViewController!.view, toItem: sourceView)
  7. self.sideBarViewController!.view.setFrameSize( NSMakeSize(100, 200))

Init data

  1. let item1 = Account(name:"ContentView1", icon:NSImage (named: NSImage.Name(rawValue: "Human_resource"))!, nameView: "ContentView1Controller", badge: "10", colorBadge: .blue)
  2. let item2 = Account(name:"ContentView2", icon:NSImage (named: NSImage.Name(rawValue: "Human_resource"))!, nameView: "ContentView2Controller", badge: "-5", colorBadge: .red)
  3. let item3 = Account(name:"ContentView3", icon:NSImage (named: NSImage.Name(rawValue: "employee"))!, nameView: "ContentView3Controller", badge: "3", colorBadge: .blue)
  4. let item4 = Account(name:"ContentView4", icon:NSImage (named: NSImage.Name(rawValue: "employee"))!, nameView: "ContentView4Controller", badge: "1", colorBadge: .blue)
  5. account1.accounts.append(item1)
  6. account1.accounts.append(item2)
  7. account2.accounts.append(item3)
  8. account2.accounts.append(item4)
  9. allSection.sections.removeAll()
  10. allSection.sections.append(account1)
  11. allSection.sections.append(account2)
  12. allSection.dump()
  13. sideBarViewController?.initData( allSection: allSection )

create all the viewController

  1. extension MainWindowController: THSideBarViewDelegate
  2. {
  3. func changeView(item : Item)
  4. {
  5. var vc = NSView()
  6. if item.nameView == "City" {
  7. nameCity = item.name
  8. NotificationCenter.send(.updateView)
  9. return
  10. }
  11. switch item.nameView
  12. {
  13. case "ContentView1Controller":
  14. vc = contentView1Controller.view
  15. case "ContentView2Controller":
  16. vc = contentView2Controller.view
  17. case "ContentView3Controller":
  18. vc = contentView3Controller.view
  19. case "ContentView4Controller":
  20. vc = contentView4Controller.view
  21. case "ContentView5Controller":
  22. vc = contentView5Controller.view
  23. case "ContentView6Controller":
  24. vc = contentView6Controller.view
  25. case "ContentView7Controller":
  26. vc = contentView7Controller.view
  27. default:
  28. vc = contentView1Controller.view
  29. }
  30. addSubview(subView: vc, toView: tableTargetView)
  31. vc.translatesAutoresizingMaskIntoConstraints = false
  32. var viewBindingsDict = [String: AnyObject]()
  33. viewBindingsDict["vc"] = vc
  34. tableTargetView.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "H:|[vc]|", options: [], metrics: nil, views: viewBindingsDict))
  35. tableTargetView.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "V:|[vc]|", options: [], metrics: nil, views: viewBindingsDict))
  36. }

Custom NSOutlineView

  1. var isSaveSection = true // Ideal for dynamic sections
  2. var colorBackGround = NSColor.blue
  3. var rowSizeStyle = NSTableView.RowSizeStyle.small
  4. var allowDragAndDrop = true