https://github.com/thierryh91200/thsidebar
NSOutlineView and badge
https://github.com/thierryh91200/thsidebar
badge codable drag-drop nsoutlineview swift5
Last synced: 3 months ago
JSON representation
NSOutlineView and badge
- Host: GitHub
- URL: https://github.com/thierryh91200/thsidebar
- Owner: thierryH91200
- License: apache-2.0
- Created: 2017-10-01T16:35:17.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2020-02-20T07:54:08.000Z (over 6 years ago)
- Last Synced: 2025-04-11T17:15:31.525Z (about 1 year ago)
- Topics: badge, codable, drag-drop, nsoutlineview, swift5
- Language: Swift
- Size: 4.56 MB
- Stars: 40
- Watchers: 2
- Forks: 6
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# SideBarDemo
NSOutlineView and badge

# THSideBar
THSideBar framework written in Swift for OS X
[](https://starchart.cc/thierryH91200/THSideBar)
# Usage
### look at example
## Initialize the THSideBar
```
var sideBarViewController : THSideBarViewController?
```
## Add THSideBar to the view hierarchy
```
self.sideBarViewController = THSideBarViewController()
addSubview(subView: (sideBarViewController?.view)!, toView: sourceView)
sideBarViewController?.delegate = self
sideBarViewController?.allowDragAndDrop = false/true
sideBarViewController?.saveSection = false/true
setUpLayoutConstraints(item: sideBarViewController!.view, toItem: sourceView)
self.sideBarViewController!.view.setFrameSize( NSMakeSize(100, 200))
```
## Init data
```
let item1 = Account(name:"ContentView1", icon:NSImage (named: NSImage.Name(rawValue: "Human_resource"))!, nameView: "ContentView1Controller", badge: "10", colorBadge: .blue)
let item2 = Account(name:"ContentView2", icon:NSImage (named: NSImage.Name(rawValue: "Human_resource"))!, nameView: "ContentView2Controller", badge: "-5", colorBadge: .red)
let item3 = Account(name:"ContentView3", icon:NSImage (named: NSImage.Name(rawValue: "employee"))!, nameView: "ContentView3Controller", badge: "3", colorBadge: .blue)
let item4 = Account(name:"ContentView4", icon:NSImage (named: NSImage.Name(rawValue: "employee"))!, nameView: "ContentView4Controller", badge: "1", colorBadge: .blue)
account1.accounts.append(item1)
account1.accounts.append(item2)
account2.accounts.append(item3)
account2.accounts.append(item4)
allSection.sections.removeAll()
allSection.sections.append(account1)
allSection.sections.append(account2)
allSection.dump()
sideBarViewController?.initData( allSection: allSection )
```
## create all the viewController
```
extension MainWindowController: THSideBarViewDelegate
{
func changeView(item : Item)
{
var vc = NSView()
if item.nameView == "City" {
nameCity = item.name
NotificationCenter.send(.updateView)
return
}
switch item.nameView
{
case "ContentView1Controller":
vc = contentView1Controller.view
case "ContentView2Controller":
vc = contentView2Controller.view
case "ContentView3Controller":
vc = contentView3Controller.view
case "ContentView4Controller":
vc = contentView4Controller.view
case "ContentView5Controller":
vc = contentView5Controller.view
case "ContentView6Controller":
vc = contentView6Controller.view
case "ContentView7Controller":
vc = contentView7Controller.view
default:
vc = contentView1Controller.view
}
addSubview(subView: vc, toView: tableTargetView)
vc.translatesAutoresizingMaskIntoConstraints = false
var viewBindingsDict = [String: AnyObject]()
viewBindingsDict["vc"] = vc
tableTargetView.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "H:|[vc]|", options: [], metrics: nil, views: viewBindingsDict))
tableTargetView.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "V:|[vc]|", options: [], metrics: nil, views: viewBindingsDict))
}
```
## Custom NSOutlineView
var isSaveSection = true // Ideal for dynamic sections
var colorBackGround = NSColor.blue
var rowSizeStyle = NSTableView.RowSizeStyle.small
var allowDragAndDrop = true