What is the relationship between NSImageView and NSImageCell?

It seems that if I create the NSImageView code in the code, there is no way to automatically scale the image proportionally if the NSImageView becomes larger than the image itself. (strange omission)

On the other hand, if I create NSImageView in IB, it somehow attaches NSImageCell to NSImageView , and NSImageCell has the ability to scale proportionally up and down, which is what I want.

But in IB, I cannot understand the relationship between NSImageView and NSImageCell . I cannot remove NSImageCell from NSImageView , and I do not see the connection in bindings or anywhere else.

How to get NSImageCell functionality when creating NSImageView in code?

Sorry if this is obvious, but I'm used to UIImageViews and they are definitely different from NSImageView .

Thanks.

+6
source share
2 answers

You can zoom in using [NSImageView setImageScaling:NSImageScaleProportionallyUpOrDown] . Have you had a problem with this? You can also access the cell for any NSControl using -cell .

Regarding the separation of cells from controls (views), this is the retention from days of much less powerful computers (some NeXT computers had only 8 MB of memory). The cells provide a lighter weight object that does not require some of the full view overhead. This is important in cases where many elements can exist, for example, in a matrix or table. Cells are designed to make copying and reuse easier, like UITableViewCell . Like UITableViewCell , the same NSCell can be reused to draw different content. Cells also share some singletones. For example, most cells typically use only one field editor ( NSTextView ). It simply moves as needed when the user selects various text fields for editing.

In a world where the first iPhone had 10x, NeXT and desktop computers typically have 1000x memory, some of the options in NSCell don't make much sense. Starting with 10.7, OS X has moved some things away from NSCell . NSTableView now supports NSView cells as well as NSCell cells. When iPhoneOS was released, UITableView started working with views from the very beginning. (Of course, the iPhone table view is negligible compared to OS X table view, so it was an easier choice for several reasons than just the available memory.)

+8
source

The reason you are confused is that the documentation on -[NSImageView setImageScaling:] is incorrect, where possible scaling options are listed. If you look at NSImageScaling , you will find another choice of NSImageScaleProportionallyUpOrDown .

+1
source

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


All Articles