我尝试创建一个搜索栏,它现在正常工作,但我无法在状态栏下找到如何让它更高一点。 搜索栏是以编程方式创建的,我使用了以下代码:
\min_{\sigma} \Bigg\{ \sum\limits_{i} \big((G(\sigma_i)\star S) - I_i\big)^2 + \gamma\Big((\delta_x \sigma_i)^2 + (\delta_y \sigma_i)^2\Big) \Bigg\}}]
答案 0 :(得分:1)
你的意思是,你想要一个导航栏位置的搜索栏。如果是这种情况,请尝试在导航栏中添加搜索栏。
试试这个
var leftNavBarButton = UIBarButtonItem(customView:Yoursearchbar)
self.navigationItem.leftBarButtonItem = leftNavBarButton
你保留了一个懒惰的UISearchBar属性
lazy var searchBar:UISearchBar = UISearchBar(frame: CGRectMake(0, 0, 200, 20))
在viewDidLoad
中searchBar.placeholder = "Your placeholder"
var leftNavBarButton = UIBarButtonItem(customView:searchBar)
self.navigationItem.leftBarButtonItem = leftNavBarButton
如果您想使用故事板,只需将搜索栏拖动为插座,然后用插座搜索栏替换惰性属性
或者只是
// create the search bar programatically since you won't be
// able to drag one onto the navigation bar
searchBar = UISearchBar()
searchBar.sizeToFit()
// the UIViewController comes with a navigationItem property
// this will automatically be initialized for you if when the
// view controller is added to a navigation controller's stack
// you just need to set the titleView to be the search bar
navigationItem.titleView = searchBar