Search code examples
cocoamacosnsimageobjective-c-runtimensbutton

How to scale axes independently at runtime on an NSButton


In Interface Builder, you can select how you want a button's image to be scaled, choosing either Axes Independent, Proportionally Down, etc. for the "Scaling" drop-down. How can I access or change this attribute of the NSButton at runtime?


Solution

  • You should be able to set that by using the button’s cell:

    NSButton *someButton;
    
    NSButtonCell *someButtonCell = [someButton cell];
    [someButtonCell setImageScaling:NSImageScaleAxesIndependently];
    

    For the list of image scaling options, see here.