简体   繁体   English

带SearchBar的iOS 11 navigationBar大小

[英]iOS 11 navigationBar size with SearchBar

If I add SearchBar to navigationBar's title - navigationBar become bigger and searchBar as well in iOS11. 如果我将SearchBar添加到navigationBar的标题中,则NavigationBar会变得更大,而iOS11中的searchBar也是如此。 Is it possible to avoid size change? 是否可以避免尺寸变化? In ios 10 there is not such thing 在ios 10中没有这种东西

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. 创建一个自定义标题视图(UIView)并将其添加到导航栏titleview中。 In your custom title view, you should override intrinsicContentSize method with UILayoutFittingExpandedSize. 在自定义标题视图中,应该使用UILayoutFittingExpandedSize覆盖internalContentSize方法。

As like Objective C: 就像目标C:

- (CGSize)intrinsicContentSize {
    return UILayoutFittingExpandedSize;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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