T
T
Toly2016-12-03 12:54:45
Cocoa
Toly, 2016-12-03 12:54:45

How to implement multi-line (multi-line) in NSTokenField?

I want to implement multi-line NSTokenFiels. That is, so that the input characters or tokens, when they reach the border of the input field, are transferred to a new line and the height of the NSTokenField is stretched so that all lines are visible, for example:
4201355426764c8cac0ea89dde73742b.png
I found on the Internet a way to implement multiline using the delegate methodcontrolTextDidChange:

- (void)controlTextDidChange:(NSNotification *)obj {
        NSRect oldTokenFieldFrame = [formatTokenField frame];
        NSSize cellSize = ;
        
        NSLog(@"%s cell width: %f cell height: %f", __func__, cellSize.width, cellSize.height);
        NSLog(@"%s frame width: %f frame height: %f", __func__, oldTokenFieldFrame.size.width, oldTokenFieldFrame.size.height);
        
        [formatTokenField setFrame:NSMakeRect(oldTokenFieldFrame.origin.x,
                                              oldTokenFieldFrame.origin.y + oldTokenFieldFrame.size.height - cellSize.height,
                                              oldTokenFieldFrame.size.width,
                                              cellSize.height)];
    }

But unfortunately this solution does not work correctly. When the characters are wrapped to a new line, the height of the NSTokenField does not increase by the height of the new line immediately, but with each new character by a third until it reaches the normal line height:
d20593baa000404c88663fd9f0290cb7.pngd7623b5f8f624aadbfc31dfe00115ea0.pngeef599c96f5b4304bcc178dc6adaddaf.png
When moving to each new line, this behavior is repeated.
Please help me figure out how to correctly implement multi-line in NSTokenField (could you provide code examples). Thank you all in advance.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question