Search code examples
iosswiftwidthuibarbuttonitemsearchbar

How to get leftBarButtonItem width?


I want to make a custom search bar in navigationBar (screenshot). I have put a UIBarButton to the left side of navigationBar in my storyboard. But searchBar will be generated from code because I don't know how to make that searchBar.

So I want to put it right after leftBarButtonItem.width +- 10/20 pixels. How to get leftBarButtonItem.width, in viewDidLoad it is zero.

Is there a way to do this? Or maybe someone can tell be better way how to create that searchBar and put it in navigationBar.


Solution

  • code

    on sim

    you can change the button's width to set the positon