0

I added a UISearch programmatically to my app and the UINavigation bar was added in interface builder. When I added the search bar it left a tiny gap between the search bar and the nav bar. Is there a way to merge them together? Thanks.

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

1 回答 1

1

如果确保 SearchBar 位于导航栏下方,我会像这样使用自动布局:

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

编辑:

我做了一些搜索,发现它不是一个差距。这是苹果用来划分事物的图像。您可以使用许多选项

1.) 搜索并销毁 - 找到 UIImageView,并将其从您的栏中删除。
在 iOS 7 中移除 UIToolbar 细线

2.) 为您的酒吧设置自定义背景

[self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
self.navigationController.navigationBar.shadowImage = [UIImage new];
于 2013-09-24T18:52:29.133 回答