1

I would like to add a progress view within my search bar, to show how much content from the search has loaded.

Here is my progress view so far in my Storyboard:

enter image description here

However, with different languages, the "cancel" button changes width, as seen here:

enter image description here

This therefore makes my ProgressView not reach the edge of the search bar. Is there an easier way to do this, or is there a way to get the size of the SearchBar's text field?


If you have any questions, please ask

George
  • 25,988
  • 10
  • 79
  • 133
  • You can make the custom searchBar. Take a UIView and put all the necessary items like, TextField and below that put a ProgressView and add the button, by pressing which you can do the searching functionality and thus can manage it well. – Bhavin Kansagara Jul 15 '18 at 16:16

1 Answers1

0

After some thinking, I had an idea. The search bar, like many other types of views, have subviews. So all I had to do was access the correct subview so I could get its width.

Here was my code:

progressView.frame.width = searchBar!.subviews[0].subviews[1].frame.width - 10
George
  • 25,988
  • 10
  • 79
  • 133
  • can i add progressview in searchbar bottom programatically ? – Virani Vivek Mar 26 '19 at 12:21
  • What do you mean? So the progress view is on the straight edge of the whole search bar? – George Mar 26 '19 at 15:48
  • @ViraniVivek Not too sure, but you may be able to use `addSubview` on one of the search bar subviews. Use trial and error to find it (by colour to find the right one), or you may be able to find something else online. – George Mar 26 '19 at 17:25
  • @ViraniVivek I stopped this project a while ago, so I have not done anything with this search bar. – George Mar 26 '19 at 17:26
  • @ViraniVivek Did you manage to solve it by adding a subview? If you couldn’t, I may create a project to test if it works or not – George Mar 27 '19 at 07:18
  • i'm still working but no solution can you help e for create like this.? – Virani Vivek Mar 27 '19 at 07:20
  • @ViraniVivek Ok, I’ll try making one when I get home at about 3:30 after school (GMT). That will be in ~8 hours, sorry ☹️ – George Mar 27 '19 at 07:22