5

I am trying to customize an NSTokenField and after trying several hours I realized that NSTokenField is not customizable enough (at least using public methods). Do you know an alternative to NSTokenField which can be easily customized?

Thanks!

Rob Keniger
  • 45,830
  • 6
  • 101
  • 134
AP.
  • 5,205
  • 7
  • 50
  • 94
  • 1
    What are you trying to do? You haven't explained why `NSTokenField` is inadequate for your needs. – Rob Keniger Jan 02 '12 at 08:15
  • 5
    Indeed. I also find `NSTokenField` terrible for customization. There is no built-in way to detect token clicks, customize token appears, etc. I am looking for something like finder / mail tokens, like this http://f.cl.ly/items/062T0Y0P0m3K1N2N2T2P/Screen%20Shot%202012-01-01%20at%209.43.44%20PM.png – Tony Jan 02 '12 at 23:56
  • I also use NSTokenField , and need to select is when user click on of the suggested text. is there any way? – Nininea Jan 17 '17 at 13:32

2 Answers2

1

How about subclassing NSTokenField and/or NSTokenFieldCell?

You could use tokenizingCharacterSet in conjonction with NSString's componentsSeparatedByCharactersInSet: to get a list of tokens and then draw them however you'd like.

You'd also be able to completely respond to mouse events however you'd like (via NSCell methods for Tracking the Mouse)

1

Been there, done that and eventually ended up writing a NSTokenField replacement from scratch. It is available on github if you want to have a look or use it in your project.

aduchate
  • 1,455
  • 1
  • 10
  • 5