Is there a way to have custom tokens inside an NSTokenField? By "custom" I mean I would like to draw them in a custom way -- custom hover, background image, etc.
It can be done without using private APIs. An NSTokenField is merely an NSTextField that makes clever use of the support for custom attachment cell support. Customizing it involves some insight into the complex NSTextStorage/NSLayoutManager/NSAttachmentCell interactions, but one good open-source implementation of customizable tokens can be seen at: https://github.com/octiplex/OEXTokenField
Yes, this is possible, but you'll have to resort to using private APIs, which you don't want if you intend on publishing your app to the Mac App Store. I have contacted Apple about this, and they have confirmed that there is no way of doing this without private APIs - if one needs difference appearance using only public APIs, one must create one's own control from scratch.
If you still want to do this using private APIs, look into BWToolkit. BWTokenField uses these private APIs to modify the token appearance. That should be a good starting point. But it takes a while to figure it all out and tweak things until one gets one's desired effect.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With