如果正下方的导航栏确保搜索栏是,我会使用自动布局像这样:
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,并将其从你的栏中删除。
Remove UIToolbar hairline in iOS 7
2)你吧
[self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
self.navigationController.navigationBar.shadowImage = [UIImage new];
由于设置自定义背景。它在constraintsWithVisualFormat中给我一个错误。它说searchBar不是视图字典中的关键。我尝试了其他一些事情,并得到相同的错误。再次感谢您的帮助。 – user1681673
再次尝试使用我添加的额外行。 – Byte
我尝试了您的更改的代码。构建的代码,但视图看起来与图片相同。 – user1681673