Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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??

like image 772
Devarshi Avatar asked Feb 25 '10 10:02

Devarshi


2 Answers

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.

like image 118
Hank Gillette Avatar answered Sep 22 '22 16:09

Hank Gillette


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.

like image 32
skabob11 Avatar answered Sep 23 '22 16:09

skabob11