31

In my app I want the user to type names into a UITextField (or equivalent) and then when they press return, it will put that word(s) in a blue bubble that's usually associated with tags. The cursor then moves to the end where they can add more "tags".

This can be seen when adding contacts in the To, CC & BCC fields in the Mail app, and also when selecting contacts in the Messages app.

How is this done? Is it something that's provided in the UIKit or available somewhere else?

Many thanks,

Michael

e.James
  • 116,942
  • 41
  • 177
  • 214
Michael Waterfall
  • 20,497
  • 27
  • 111
  • 168
  • You might also take a look at [TITokenField](https://github.com/thermogl/TITokenField). – madrogue Mar 18 '11 at 15:01
  • I came across this one that looks good: https://github.com/jasarien/JSTokenField but I didn't try it myself. – yonel Oct 11 '11 at 07:20

5 Answers5

8

Venmo just open sourced their token field.

https://github.com/venmo/VENTokenField.git

andrewmclean
  • 427
  • 3
  • 15
6

edited:

The equivalent control in desktop Cocoa is an NSTokenField, but there doesn't seem to be an equivalent for Cocoa Touch.

rptwsthi
  • 10,094
  • 10
  • 68
  • 109
e.James
  • 116,942
  • 41
  • 177
  • 214
3

Since iOS 13 there exists UISearchTextField.

https://developer.apple.com/documentation/uikit/uisearchtextfield

You can see that component in action in the Photos App. That should fit for many use cases. By removing the leftView you can also get rid of the search icon.

But be aware: You can‘t mix text and tokens at various positions.

From the docs:

Tokens always occur contiguously before any text in the search field.

orschaef
  • 1,287
  • 10
  • 27
2

Adding this here for reference:

Feel free to check out TaggerKit (a library I made), it's more or less what OP was talking about. You can basically add tags functionality to your app by just adding a view and a couple of properties.

nknr
  • 123
  • 6
-1

I dont think you can do it with any built in functionality in the SDK, never seen such a feature. What you could do however is implement it yourself, have some custom blue button with some text over it, and when the user hits return you can have some code that takes the text and returns you the button that you need, shouldnt be too bad to implement

Daniel
  • 22,363
  • 9
  • 64
  • 71