我正在尝试实现以下内容:
两个按钮用户和聊天点击时会出现相应的视图控制器.我想在导航栏上显示这些按钮.
这是我在页面视图控制器类中编写的代码
vIEwDIDLoad() let storyBoard = UIStoryboard(name: "Main",bundle: nil) let vc1 = storyBoard.instantiateVIEwControllerWithIDentifIEr("users") let vc2 = storyBoard.instantiateVIEwControllerWithIDentifIEr("chat") vcArray = [vc1,vc2] self.setVIEwControllers([vc1],direction: .Forward,animated: true,completion: nil) let button1 = UIbutton(frame: CGRectMake(0,30,self.vIEw.frame.wIDth/2,30)) let button2 = UIbutton(frame: CGRectMake(self.vIEw.frame.wIDth/2+1,30)) button1.setTitle("Users",forState: .normal) button2.setTitle("Chat",forState: .normal) self.navigationController?.navigationbar.topItem?.TitleVIEw?.addSubvIEw(button1) self.navigationController?.navigationbar.topItem?.TitleVIEw?.addSubvIEw(button2)
不幸的是,导航栏中没有任何按钮.
事实上,我甚至无法为导航栏指定标题.我怎样才能解决这个问题?
谢谢
解决方法 您可以在导航栏的右侧添加多个按钮,如下所示let editimage = UIImage(named: "First")!let searchImage = UIImage(named: "Second")!let editbutton = UIbarbuttonItem(image: editimage,style: .Plain,target: self,action: "dIDTapEditbutton:")let searchbutton = UIbarbuttonItem(image: searchImage,action: "dIDTapSearchbutton:")navigationItem.rightbarbuttonItems = [editbutton,searchbutton]
要么
self.navigationController?.navigationbar?.navigationItem.rightbarbuttonItems = [editbutton,searchbutton]
@H_404_49@ 总结If you want to make it look in the centre on the navigation bar,you can use image with appropriate wIDth so that it scales towards the center.
以上是内存溢出为你收集整理的ios – 如何在UIPageViewController中显示导航栏上的按钮?全部内容,希望文章能够帮你解决ios – 如何在UIPageViewController中显示导航栏上的按钮?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)