在网上找了很久没看到解决方法,所以想记录一下。网上普遍方法为
[self.heightAnchor constraintEqualToConstant:44].active = YES;
但是这个方法在iOS 13上并不生效,最简单有效改变searchbar的宽高方法:
UIView*titleView = [[UIViewalloc]initWithFrame:CGRectMake(0,0,300,44)];
UISearchBar*searchBar = [[UISearchBaralloc]initWithFrame:titleView.bounds];
searchBar.placeholder=@"搜索";
searchBar.searchBarStyle = UISearchBarStyleMinimal;
[titleViewaddSubview:searchBar];
self.navigationItem.titleView = titleView;
想了下searchBar导致导航栏发生变化,但是view并不会,可以把view设为titleview,再添加searchBar在view上,完美解决。
网友评论