Search code examples
objective-ccocoansimagensimageview

NSImageView size vs NSImage size


Does the size of the image used for an NSImageView need to be the same dimensions as the image view?

As an example, when I have an icon image with dimensions like 64px by 64px then I make sure the NSImageView that displays the image is also 64px by 64px. However, if I have an NSImageView that is 48px by 48px then I would make sure I have an image that is 48px by 48px for that image view. Both of these images are the same icon, but one is larger than the other. So instead of having two separate images in the app (which can increase the app size if there are a lot of images), I was wondering if I could just have one image (the 64x64 image) and use that larger image for the smaller sized NSImageViews.


Solution

  • No, they don't need to be the same size. You can change the NSImageView's imageScaling and imageAlignment to ensure the NSImage resizes nicely to fill the NSImageView.

    See Apple's documentation for further details.