简体   繁体   中英

iOS 11 navigationBar size with SearchBar

If I add SearchBar to navigationBar's title - navigationBar become bigger and searchBar as well in iOS11. Is it possible to avoid size change? In ios 10 there is not such thing

I add it by code

navigationBar.titleView = searchBar

在此处输入图片说明

Initialize the searchbar like this

let searchBar = UISearchBar(frame: CGRect(x: 20, y: 0, width: UIScreen.main.bounds.width-40, height: 40)) 
//Change x,y,width,height according to your need

Hope this will help you

Create a custom title view (UIView) & add into your navigation bar titleview. In your custom title view, you should override intrinsicContentSize method with UILayoutFittingExpandedSize.

As like Objective C:

- (CGSize)intrinsicContentSize {
    return UILayoutFittingExpandedSize;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM