NSToolbarItem Image Scaling

Why is this happening:

GNpas.png

As you can see, in "Allowed Toolbar Elements" the image looks great for the "PHP" toolbar element, and when it is actually on the toolbar, it looks weird.

thanks

+3
source share
3 answers

This is found in the documentation:

sizeMode . , , , , , icns tiff. . , . , , . . ( )

, fiddling NSToolbarItem minSize maxSize.

+7

"Image Well" (NSImageView) . ( , ).

, NSToolbarItem: NSImageView NSToolbarItem. , /, .

Tipp: NSSegmentedControls NSControls : -)

+3

After you set the view to NSToolbarItem, the target and action of the toolbar item are ignored, so view should trigger the action. Since NSImageView does not handle clicks, you should use NSButton, not:

NSToolbarItem *toolbarItem = [[NSToolbarItem alloc] initWithItemIdentifier:@"someToolbarItem"];
NSButton *button = [NSButton new];
button.image = [[NSBundle mainBundle] imageForResource:@"some_image"];
button.target = self;
button.action = @selector(someAction:);
((NSButtonCell*)button.cell).highlightsBy = NSNoCellMask; // to stop the button highlighting when you press it
button.bordered = NO;
toolbarItem.view = button;
0
source

Source: https://habr.com/ru/post/1720367/


All Articles