iOS 11里,在导航栏直接设置searchbar为titleView,由于searchbar本身的圆角效果,会导致searchbar的高度变的比设计的要大,进而导致navigationbar的高度也发生变化,不再是最初的44.,可以使用下面的方法来解决这个问题
UIView *titleView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, 32)];
UISearchBar *searchBar = [[UISearchBar alloc] initWithFrame:titleView.bounds];
searchBar.placeholder = @"搜索";
searchBar.searchBarStyle = UISearchBarStyleMinimal;
[titleView addSubview:searchBar];
self.navigationItem.titleView = titleView;
stackoverflow链接
网友评论