gpt4 book ai didi

ios - 如何更改搜索栏的高度? swift

转载 作者:搜寻专家 更新时间:2023-10-31 19:30:53 25 4
gpt4 key购买 nike

我有这个:

http://postimg.cc/image/oepn8hhzd/

我需要这个:

http://postimg.cc/image/4bacislw5/

我的搜索栏代码

var searchBar:UISearchBar = UISearchBar(frame: CGRectMake(0, 0, 200, 0))


searchBar.tintColor = UIColor.blueColor()
self.searchBar.layer.borderColor = UIColor.blueColor().CGColor
self.searchBar.layer.borderWidth = 0.5
self.searchBar.layer.cornerRadius = 5.0
self.searchBar.clipsToBounds = true
searchBar.placeholder = "Search for cities"
searchBar.sizeToFit()


self.searchBar.setImage(UIImage(named: "Search@3x"), forSearchBarIcon: UISearchBarIcon.Search, state: UIControlState.Normal)
self.searchBar.setImage(UIImage(named: "Close@3x"), forSearchBarIcon: UISearchBarIcon.Clear, state: UIControlState.Normal)

searchBar.delegate = self


var leftNavBarButton = UIBarButtonItem(customView: searchBar)
self.navigationItem.leftBarButtonItem = leftNavBarButton

有什么想法吗?(对不起链接,我不能插入图片)

最佳答案

您可以使用另一个 View 作为导航栏标题,并将搜索栏放在其中。

let searchController = UISearchController(searchResultsController: nil)
searchController.hidesNavigationBarDuringPresentation = false
searchController.dimsBackgroundDuringPresentation = false
searchController.searchBar.delegate = self

let frame = CGRect(x: 0, y: 0, width: 100, height: 44)
let titleView = UIView(frame: frame)
searchController.searchBar.backgroundImage = UIImage()
searchController.searchBar.frame = frame
titleView.addSubview(searchController.searchBar)
navigationItem.titleView = titleView

希望这会有所帮助。

关于ios - 如何更改搜索栏的高度? swift ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31446458/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com