本文介绍了如何更改搜索栏的高度?迅速的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个:
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
有什么想法吗?(抱歉链接,我无法插入图片)
Any ideas?(Sorry for links, I cannot insert images)
推荐答案
您可以使用另一个视图作为导航栏标题并将搜索栏放置在其中.
You can use another view as navigation bar title and place search bar inside it.
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
希望这会有所帮助.
这篇关于如何更改搜索栏的高度?迅速的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!