T
T
Toly2016-11-27 12:49:49
Cocoa
Toly, 2016-11-27 12:49:49

How to add NSButton button to NSTokenField?

I want to add a button in my application in the NSTokenField field, for example, something like this:
1f81ff0b70154ef48e62fe2d9be1c31a.png
That is, in NSTokenField there is a plus sign button that should perform some action, for example, a pop-up menu with a choice of tokens that can be added to the NSTokenField field.
I created a button programmatically and added it to NSTokenField:

NSButton *button = ];
[button setButtonType:NSMomentaryPushInButton];
[button setBezelStyle:NSSmallSquareBezelStyle];
[button setTarget:self];
[button setAction:@selector(action:)];
[formatTokenField addSubview:button];

the button was added normally:
c5f1b2d0a1c34d2d9ea18c713363fe46.png
but when I try to enter characters in the NSTokenField, the input area overlaps my button:
2a86e645866d43adbc92ea641f3486f8.png
Please help me figure out how to correctly add buttons to the NSTokenField and what needs to be done so that the input area does not overlap the added buttons (could you provide code examples). Thank you all in advance.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
Petrushka, 2016-11-27
@petruska

Maybe it will be easier to write your own class?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question