user4591756
user4591756

Reputation:

Styling text in a SearchBar / TextField iOS Swift

I'm working on an iOS app using swift. I have a SearchBar/Textview (i've tried with both) and want to split each search term a user types in, into a bubble similar to pinterest where the user can later press the cross to remove certain ones.

How do I start with this? I can only seem to change the background of the whole TextField instead of just for each word.

Here's a sample of what I am trying to achieve.

Here's a sample of what I am trying to achieve http://www.standingdog.com/blog/wp-content/uploads/2014/04/pinterest-guided-search-screen-shot.jpg

Upvotes: 1

Views: 513

Answers (1)

Sulthan
Sulthan

Reputation: 130122

This is not really a formatted text. What they are doing is different. When a space/enter is typed in (and you can detect that by the UITextField delegate), you take the currently written text and create a view from it.

The structure of that view will be similar to the following:

+ view
   + label with the text
   + x (remove) button

You will then add this view to a container view. The purpose of this view is to keep the search term views in a list.

You can then assign this container view to [UITextField leftView].

Of course, then you have to handle removal, backspace etc.

Upvotes: 1

Related Questions