Skip to content

Latest commit

 

History

History
111 lines (83 loc) · 2.93 KB

README.md

File metadata and controls

111 lines (83 loc) · 2.93 KB

testOutline

Just an exercice for itemForPersistentObject and persistentObjectForItem

itemForPersistentObject

When the outline view is restoring the saved expanded items, this method is called for each expanded item, to translate the archived object to an outline view item.

persistentObjectForItem

When the outline view is saving the expanded items, this method is called for each expanded item, to translate the outline view item to an archived object.

nstableview change isselected text color NSTableRowView

1. Start with subclassing NSTableRowView

class CategoryTableRowView: NSTableRowView {

override func drawSelection(in dirtyRect: NSRect) {
    if selectionHighlightStyle != .none {
        let selectionRect = bounds.insetBy(dx: 2.5, dy: 2.5)
        NSColor(calibratedRed: 61.0/255.0, green: 159.0/255.0, blue: 219.0/255.0, alpha: 1.0).setStroke()
        NSColor(calibratedWhite: 1.0, alpha: 1.0).setFill()
        let selectionPath = NSBezierPath(roundedRect: selectionRect, xRadius: 25, yRadius: 25)
        selectionPath.fill()
        selectionPath.stroke()
    }
  }
}

2. Return custom CategoryTableRowView() in the NSTableViewDelegate method

func tableView(_ tableView: NSTableView, rowViewForRow row: Int) -> NSTableRowView? {
      return CategoryTableRowView()
}

3. Make sure you have selectionHighlightStyle to regular in your ViewController class

override func viewDidLoad() {
     super.viewDidLoad()
     self.outlineView.selectionHighlightStyle = .regular
}

4. To set the textColor, create a subclass of NSTableCellView

override the backgroundStyle property and set the desired color for the text.

class CategoryCellView: NSTableCellView {
    
    var oldColor : NSColor? = nil
    var oldFont : NSFont? = nil

    override var backgroundStyle: NSView.BackgroundStyle {
        willSet{
            if newValue == .emphasized {
                
                textField?.font = NSFont.systemFont(ofSize: 14)
                textField?.textColor = NSColor.textColor
            } else {
                if oldColor == nil {
                    oldColor = textField?.textColor!
                    oldFont = textField?.font
                }
                textField?.textColor = oldColor
                textField?.font = oldFont
            }
            super.backgroundStyle = newValue
        }
    }
}

5. Set custom class inside storyboard

Sample

Normal

Sample

Select light

Sample

Select dark