If making sure that SearchBar is right under the navigation bar, I would use autolayout like so:
self.searchBar = [[UISearchBar alloc] init];
self.searchBar.translatesAutoresizingMaskIntoConstraints = NO;
self.searchBar.delegate = self;
self.searchBar.showsCancelButton = NO;
[self.view addSubview:self.searchBar];
id topLayoutGuide = self.topLayoutGuide;
UISearchBar *searchBar = self.searchBar; //updated
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[searchBar]|" options:0 metrics:0 views:NSDictionaryOfVariableBindings(searchBar)]];
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[topLayoutGuide][searchBar]" options:0 metrics:0 views:NSDictionaryOfVariableBindings(searchBar, topLayoutGuide)]];
Edit:
I did some searching and found that it is not a gap. It is an image Apple uses to divide things into place. There are many options you can approach
1.) Search and destroy - find the UIImageView, and remove it from your bar.
Remove UIToolbar hairline in iOS 7
2.) Set custom background for your bar
[self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
self.navigationController.navigationBar.shadowImage = [UIImage new];