You could manage the button state yourself without a lot of code.

@IBOutlet var button1: NSButton    // tag = 0
...
@IBOutlet var buttonN: NSButton    // tag = N - 1

private var selectedPaletteButtonIndex: Int = 0
private var paletteButtons: [NSButton]

override func viewDidLoad()
{
    super.viewDidLoad()

    paletteButtons =
    [
        button1,
        ...
        buttonN
    ]

    paletteButtons[selectedPaletteButtonIndex].state = .on
}

@IBAction func paletteChanged(_ button: NSButton)
{
    let newSelectedPaletteButtonIndex = button.tag

    if selectedPaletteButtonIndex != newSelectedPaletteButtonIndex
    {
        paletteButtons[selectedPaletteButtonIndex].state = .off
        paletteButtons[newSelectedPaletteButtonIndex].state = .on

        selectedPaletteButtonIndex = newSelectedPaletteButtonIndex
    }
}


> On Dec 20, 2017, at 5:04 PM, Casey McDermott <supp...@turtlesoft.com> wrote:
> 
> Is there a way to have a palette of icon buttons act like radio buttons, 
> without use of the deprecated NSMatrix?  The goal is something like the 
> drawing tool palette in the Sketch sample app (or ancient MacDraw).
> 
> In IB, it is not possible to add an image to a NSButton with style radio. It 
> automatically changes to a bevel button when the image is added. Likewise, 
> with style rectangle, the type can't be radio.
> 
> Thanks,
> 
> Casey McD

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to