Search code examples
cocoamacosnsbutton

Lost in NSButton types and alternate images


I’d like to have an NSButton with an image and an alternate image. The alternate image should be displayed while the button is being pressed and I’d also like to display the alternate image from code, calling something like [button setSelected:YES]. Is this possible without monkeing with the alternateImage property by hand?


Solution

  • This is possible without manually changing the button's image:

    In Interface Builder (xib/nib Editor) set the Type of NSButton to "Toggle" and the image will automatically change to the alternate image/title.

    Set the type to Toggle to use the alternate image