Lost in NSButton types and alternate images

旧城冷巷雨未停 提交于 2019-12-05 07:02:32

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.

You can use a NSButton with type set to NSToggleButton and then switch between the image and the alternateImage using the NSOnState / NSOffState states of the NSButton.

NSButton* theButton = [[NSButton alloc] initWithFrame:....];
theButton.image = .....
theButton.alternateImage = .....
theButton.state = NSOffState; // displays the image
theButton.state = NSOnState; // displays the alternateImage
lbrndnr

The easiest way is to switch between the two images:

@implementation NSButton (Select)

- (void) setSelected: (BOOL) yn
{
    NSImage *const tmp = [self image];
    [self setImage:[self alternateImage]];
    [self setAlternateImage:tmp];
}

@end
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!