Reputation:
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?
Upvotes: 5
Views: 2018
Reputation: 456
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)
Upvotes: 0
Reputation: 5064
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
How to remove UINavigatonItem's border line
Upvotes: 1
Reputation: 259
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.
Upvotes: 4
Reputation: 20975
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];
}
Upvotes: 6
Reputation: 301
The white line is probably the shadowImage of navigation bar.
Try setting it as:
self.navigationController.navigationBar.shadowImage = [UIImage new];
Upvotes: 2