1

I'm just getting into development on mac os and I made a simple app for the touch bar that allows you to change the color (with a nscolorpicker) of a label that is also on the touch bar.

Now I would like to get the same effect on the actual window like so: I change the color using the picker on the touch bar and the color of the colorwell in the window changes as well.

This is the code that I currently have for the touch bar actions:

import Cocoa

@available(OSX 10.12.2, *)
class MainWindowController: NSWindowController {


@IBOutlet weak var cptHello: NSColorPickerTouchBarItem!
@IBOutlet var lblHello: NSTextField!
override func windowDidLoad() {
    super.windowDidLoad()

    // Implement this method to handle any initialization after your window controller's window has been loaded from its nib file.

    cptHello.color = NSColor.white

    setCol()
}

func setCol(){

    lblHello.textColor = cptHello.color
}

@IBAction func colorPicked(_ sender: Any) {

    setCol()

}
}

This piece of code resides in MainWindowController.swift which is paired with the window controller.

In the view controller, I have a single NSColorWell that I would like to change the color for inside the function "setCol()". I created an outlet in the view controller for it like so:

@IBOutlet var cwHello: NSColorWell!

So ideally what I want to achieve is something like this:

func setCol(){

    lblHello.textColor = cptHello.color
    ViewController.cwHello.color = cptHello.color

}

Can this be done at all?

user265889
  • 667
  • 1
  • 10
  • 24

0 Answers0