how to customize NSTokenField like in "To/ CC" fields in mac mail?
Asked Answered
C

2

6

I am able to work with NSTokenField, it is easy to use.. but I want your suggestions on how can I customize it just like it is in "To/ CC" fields in mac mail ie. when no. of tokens in a token field increases height of "To" field gets increased to a certain limit then a vertical scroller starts appearing!

By default when we use a token field neither its height gets increased nor a vertical scroller appears! I tried different combinations in IB but I could not obtain mac mail like functionality.

Can anyone suggest me some solution for it??

Carefree answered 25/2, 2010 at 10:47 Comment(0)
T
4

You'll have to subclass NSTokenField to get the functionality you want. Be sure and call setWraps: YES.

When the contents of the token field changes, you'll have to calculate the required size of your token field and resize it yourself. Same with adding a scroll bar. After the height of the token field reaches some size, you'll insert a scroll view into the field. Conversely, when the recalculating of the token field size is less than the critical size, you'll remove the scroll view.

This is a considerable amount of work (I've found) to get it work correctly. Apple says that the NSTokenField "provides tokenized editing similar to the address field in the Mail application", but it's really not that similar at all since it doesn't have resizing built in and drag and drop is problematical for anything except text.

Thebaid answered 17/6, 2010 at 21:9 Comment(0)
V
2

I was able to achieve this using IFVerticallyExpandingTextField. Because NSTokenField inherits from NSTextField, I made IFVerticallyExpandingTextField inherit from NSTokenField and then subclassed IFVerticallExpandingTextField to implement all the things I needed to do with my version of NSTokenField.

This should just be a drop in. Right away it should start working.

Verdi answered 17/9, 2010 at 16:5 Comment(1)
The change of 'ownership' of cocoadev.com has left it a bit wonky. Nontheless a simple google "site:cocoadev.com" IFVerticallyExpandingTextField finds the (very badly formatted) code: cocoadev.com/IFVerticallyExpandingTextFieldZeebrugge

© 2022 - 2024 — McMap. All rights reserved.