gpt4 book ai didi

ios - 自定义 UISearchBar

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:07:59 27 4
gpt4 key购买 nike

我很好奇人们是如何制作自己的搜索界面的,我真的不喜欢这个标准,所以决定自己写一个。我不知道如何编写我自己的,所以我要求提示,在那里你可以看到我所知道的一切 - 这就是创建你自己的 UIView 所需要的。

我想做的事的一个例子enter image description here

enter image description here

最佳答案

我曾经做过类似的东西,如果你使用 swift ,研究这段代码,它会对你有所帮助,如果这没有帮助请进一步解释。

enter image description here

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

}

关于ios - 自定义 UISearchBar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35615550/

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