0
votes

I have a NSToolbar and I want to draw at the items. This works, if I use a NSView as item instead of an Image Toolbar Item. The problem: A NSView doesn't respond, if I connect it to an IBAction.

How can I subclass an Image Toolbar Item, so that I can completely draw on it for myself? (I want to draw the image by myself)

1
Draw what on NSToolbarItem?El Tomato
Some NSBezierPath for example? ;) Something like thisLupurus
Draw whatever you have on an instance of NSView. Then add it to an NSToolbarItem.El Tomato
That's what I did and it works, but if I connect the Toolbaritem with an IBAction, the action never will be firedLupurus
I don't know what you have done since I don't see a single line of code.El Tomato

1 Answers

0
votes

I solved it this way:

I subclassed NSToolbarItem and I just draw on the image like this:

class CustomToolbarItem: NSToolbarItem {

    override func awakeFromNib() {
        image = NSImage(size: NSSize(width: maxSize.width, height: maxSize.height), flipped: false, drawingHandler: { (rect) -> Bool in
            //... drawing methods
            return true
        })
    }
}