ios - 自定义 UISearchBar
<p><p>我很好奇人们如何制作自己的搜索界面,我真的不喜欢标准并决定自己编写。我不知道如何编写自己的,所以我要求提示,您可以在哪里看到我所知道的所有内容 - 这就是创建自己的 <code>UIView</code> 所需要的。</p>
<p>我想做的一个例子<a href="/image/rMyjD.jpg" rel="noreferrer noopener nofollow"><img src="/image/rMyjD.jpg" alt="enter image description here"/></a> </p>
<p> <a href="/image/ATqqu.jpg" rel="noreferrer noopener nofollow"><img src="/image/ATqqu.jpg" alt="enter image description here"/></a> </p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>我曾经做过类似的事情,如果你使用 swift,研究这段代码,它会对你有所帮助,如果这没有帮助,请进一步解释。</p>
<p> <a href="/image/aOE3D.png" rel="noreferrer noopener nofollow"><img src="/image/aOE3D.png" alt="enter image description here"/></a> </p>
<pre><code>func addNavigationBar()
{
self.navigationController!.navigationBar.barTintColor = UIColor.blackColor()
let centerView = UIView(frame:CGRectMake(0, 0, 100, 30))
let logo = UIImage(named: "logo.png")
var btnMiddle = UIButton(frame: CGRectMake(0,5,80,20))
btnMiddle.setBackgroundImage(logo, forState: UIControlState.Normal)
btnMiddle.addTarget(self, action: "goBackHome", forControlEvents: UIControlEvents.TouchUpInside)
centerView.addSubview(btnMiddle)
self.navigationItem.titleView = centerView
var buttonDimension = CGFloat(25)
let rightView = UIView(frame:CGRectMake(0, 0, 100, 30))
let leftView = UIView(frame:CGRectMake(0, 0, 100, 30))
let btnr1 = UIButton(frame: CGRectMake(30,0,buttonDimension,buttonDimension))
btnr1.setBackgroundImage(UIImage(named: "_barSearch.png"), forState: UIControlState.Normal)
btnr1.addTarget(self, action: "search", forControlEvents: UIControlEvents.TouchUpInside)
rightView.addSubview(btnr1)
let btnr2 = UIButton(frame: CGRectMake(80,0,buttonDimension,buttonDimension))
btnr2.setBackgroundImage(UIImage(named: "_barSettinges.png"), forState: UIControlState.Normal)
btnr2.addTarget(self, action: "settinges", forControlEvents: UIControlEvents.TouchUpInside)
rightView.addSubview(btnr2)
let btnl3 = UIButton(frame: CGRectMake(0,0,buttonDimension,buttonDimension))
btnl3.setBackgroundImage(UIImage(named: "_barMenu.png"), forState: UIControlState.Normal)
btnl3.addTarget(self, action: "menu", forControlEvents: UIControlEvents.TouchUpInside)
leftView.addSubview(btnl3)
let rightBtn = UIBarButtonItem(customView: rightView)
self.navigationItem.rightBarButtonItem = rightBtn
let leftBtn = UIBarButtonItem(customView: leftView)
self.navigationItem.leftBarButtonItem = leftBtn
}
</code></pre></p>
<p style="font-size: 20px;">关于ios - 自定义 UISearchBar,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/35615550/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/35615550/
</a>
</p>
页:
[1]