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 scr开发者_Go百科oller appears! I tried different combinations in IB but I could not obtain mac mail like functionality.
Can anyone suggest me some solution for it??
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.
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.
精彩评论