UINavigationBar和UISearchBar之间的差距很小

时间:2013-09-24 18:36:01

标签: ios interface-builder uinavigationbar uisearchbar

我以编程方式将UISearch添加到我的应用程序中,并在界面构建器中添加了UINavigation栏。当我添加搜索栏时,它在搜索栏和导航栏之间留下了一个小小的间隙。有没有办法将它们合并在一起?谢谢。

Screenshot

self.searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0.0, 0.0,    self.view.bounds.size.width, 44.0)];
self.searchBar.delegate = self;
self.searchBar.autoresizingMask = UIViewAutoresizingFlexibleWidth;
self.searchBar.showsCancelButton = NO;
[self.view addSubview:self.searchBar];

1 个答案:

答案 0 :(得分:1)

如果确保SearchBar在导航栏下方,我会像这样使用autolayout:

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)]];

编辑:

我做了一些搜索,发现这不是一个差距。这是Apple用来将事物划分到位的形象。您可以使用许多选项

1。)搜索并销毁 - 找到UIImageView,然后将其从栏中删除 Remove UIToolbar hairline in iOS 7

2.。)为栏设置自定义背景

[self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
self.navigationController.navigationBar.shadowImage = [UIImage new];