I have a UITableViewController
with a UISearchDisplayController
and UISearchBar
. I'm seeing a white line under the navbar when I present the view in a UITabBarController
. When I present the view modally in a UINavigationController
, the line is either gray or black (I can't tell) and it looks perfectly normal. Any ideas?
Asked
Active
Viewed 1,961 times
5

Deepesh
- 8,065
- 3
- 28
- 45
6 Answers
6
I had the same problem, couldn't figure out from where it did came from (it was present everywhere and it was NOT the shadowImage
), ended up with the following fix (in my UINavigationController
subclass)
// Fixes strange line under NavigationBar
{
UIView * view = [[UIView alloc] init];
view.backgroundColor = self.navigationBar.barTintColor;
CGRect rect = view.frame;
rect.origin.x = 0.f;
rect.origin.y = self.navigationBar.frame.size.height;
rect.size.width = self.navigationBar.frame.size.width;
rect.size.height = 1.f;
view.frame = rect;
[self.navigationBar addSubview:view];
}

Peter Lapisu
- 19,915
- 16
- 123
- 179
4
I had the same problem too, after trying with a lot of methods,I find this way solved my problem
[[UISearchBar appearance] setBackgroundColor:[UIColor yourColor]];
write it in your viewDidLoad.

Silence.Kidd
- 259
- 2
- 3
-
Works for me in iOS 9, Thanks! – Rodrigo Moreno Nov 27 '15 at 07:27
2
The white line is probably the shadowImage of navigation bar.
Try setting it as:
self.navigationController.navigationBar.shadowImage = [UIImage new];

Ratan
- 301
- 2
- 13
1
Use following line of the code :
UIView *overlayView = [[UIView alloc] initWithFrame:CGRectMake(0, 43, 320, 1)];
[overlayView setBackgroundColor:[UIColor whiteColor]]; // set color accordingly
[navBar addSubview:overlayView]; // navBar is your UINavigationBar instance
[overlayView release];
here is my posted Answer : Horizontal Separator NavBar IOS 7

Community
- 1
- 1

Divya Bhaloidiya
- 5,018
- 2
- 25
- 45
0
Swift version of Divya's answers
let hideLineView = UIView(frame: CGRect(x: 0, y: navigationController!.navigationBar.frame.size.height, width: view.frame.size.width, height: 1))
hideLineView.backgroundColor = UIColor.white
navigationController!.navigationBar.addSubview(hideLineView)

Espen Birk
- 436
- 1
- 5
- 16