I have a UISearchBar in a titleView of Navigation bar, i did use [searchBar sizetofit] and create UISearchBar with frame of CGRectZero. But there is a small empty space on the left and right size of the UISearchBar inside titleView of Navigation.
theSearchBar = [[UISearchBar alloc] initWithFrame:CGRectZero];
theSearchBar.delegate = self;
self.navigationItem.titleView = self.theSearchBar;
[self.theSearchBar sizeToFit];
self.navigationItem.titleView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
//Change color of UISearchBar
theSearchBar.tintColor = [UIColor colorWithRed:102.0f/255.0f green:73.0f/255.0f
blue:126.0f/255.0f alpha:1.0f];
//Change color of NavigationBarItem
self.navigationController.navigationBar.tintColor = [UIColor colorWithRed:102.0f/255.0f
green:73.0f/255.0f blue:126.0f/255.0f alpha:1.0f];
//Set background image for navigation bar
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:
@"SearchBar.png"] forBarMetrics:UIBarMetricsDefault];
I would like the UISearchBar fully fill the width of screen in both portrait and landscape..
Any help is really appreciated :)
Im using Xcode 4.5, iOS 6, with iPhone 5.
I only want to use navigationItem.titleView to host my UISearchBar, i think its better this way.
Thanks all