ios – 如何在导航栏Swift右侧添加自定义视图?

ios – 如何在导航栏Swift右侧添加自定义视图?,第1张

概述我正在尝试在UINavigationBar的右侧添加自定义视图.我尝试的是以下内容,但视图没有显示出来!请帮助,提前谢谢! let viewOnrightButton = UIView(frame: CGRect(x: 2, y: 2, width: 60, height: 22)) // viewOnrightButton.frame = CGRectMake(2, 2, 60, 22)vi 我正在尝试在UINavigationbar的右侧添加自定义视图.我尝试的是以下内容,但视图没有显示出来!请帮助,提前谢谢!

let vIEwOnrightbutton = UIVIEw(frame: CGRect(x: 2,y: 2,wIDth: 60,height: 22)) // vIEwOnrightbutton.frame = CGRectMake(2,2,60,22)vIEwOnrightbutton.layer.cornerRadius = 2vIEwOnrightbutton.backgroundcolor = UIcolor(red: 0.961,green: 0.827,blue: 0.239,Alpha: 1.00)lblNumbersOfBanana.frame = CGRectMake(2,1,vIEwOnrightbutton.frame.wIDth-20,20)lblNumbersOfBanana.text = "001"var bananaimgVIEw = UIImageVIEw(frame: CGRect(x: vIEwOnrightbutton.frame.wIDth-22,y: 0,wIDth: 20,height: 20)) //  bananaimgVIEw.frame = CGRectMake(vIEwOnrightbutton.frame.wIDth-22,20,20)bananaimgVIEw.image = UIImage(named: "banana")vIEwOnrightbutton.addSubvIEw(lblNumbersOfBanana)vIEwOnrightbutton.addSubvIEw(bananaimgVIEw)self.navigationItem.rightbarbuttonItem?.customVIEw = vIEwOnrightbutton
解决方法 //创建uivIEw并添加三个自定义按钮

func addRightbutton(){    let vIEwFN = UIVIEw(frame: CGRectMake(0,180,40))        vIEwFN.backgroundcolor = UIcolor.yellowcolor()    let button1 = UIbutton(frame: CGRectMake(0,8,40,20))    button1.setimage(UIImage(named: "notification"),forState: UIControlState.normal)    button1.setTitle("one",forState: .normal)    button1.addTarget(self,action: #selector(self.dIDTapOnRightbutton),forControlEvents: UIControlEvents.touchUpInsIDe)    let button2 = UIbutton(frame: CGRectMake(40,20))    button2.setimage(UIImage(named: "notification"),forState: UIControlState.normal)    button2.setTitle("tow",forState: .normal)    let button3 = UIbutton(frame: CGRectMake(80,20))     button3.setimage(UIImage(named: "notification"),forState: UIControlState.normal)    button3.setTitle("three",forState: .normal)    button3.addTarget(self,forControlEvents: UIControlEvents.touchUpInsIDe)    vIEwFN.addSubvIEw(button1)    vIEwFN.addSubvIEw(button2)    vIEwFN.addSubvIEw(button3)    let rightbarbutton = UIbarbuttonItem(customVIEw: vIEwFN)    self.navigationItem.rightbarbuttonItem = rightbarbutton}
总结

以上是内存溢出为你收集整理的ios – 如何在导航栏Swift右侧添加自定义视图?全部内容,希望文章能够帮你解决ios – 如何在导航栏Swift右侧添加自定义视图?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1005597.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-22
下一篇 2022-05-22

发表评论

登录后才能评论

评论列表(0条)

保存