简体   繁体   English

我如何在导航栏ios的中心获得两个按钮

[英]How do I get two buttons in the center of a navigation bar ios

在此处输入图片说明

I would like to implement the following image in Swift for my navigation bar. 我想在Swift中为导航栏实现以下图像。 I have tried the following code, however, it just stack the buttons on top of each other 我尝试了以下代码,但是,它只是将按钮堆叠在一起

let fromButton:UIButton = UIButton(frame: CGRectMake(0,0,80,44))
let toButton:UIButton = UIButton(frame: CGRectMake(80,0,80,44))

fromButtonView.bounds = fromButton.frame
fromButton.addSubview(fromButtonView)

toButtonView.bounds = toButton.frame
toButton.addSubview(toButtonView)

var myView:UIView = UIView(frame: CGRectMake(0,0,160,44))

myView.addSubview(toButton)
myView.addSubview(fromButton)

self.navigationItem.titleView = myView

fromButtonView and toButtonView are variables with the views implemented as xibs. fromButtonView和toButtonView是变量,其视图实现为xibs。

The resulting navigation header looks as follows, can't figure out where I am going awry. 产生的导航标题如下所示,无法弄清楚我要去哪里。 The views are stacking on top of each other. 视图相互堆叠。

在此处输入图片说明

let testFrame : CGRect = CGRectMake(0,0,180,40)

var buttonView: UIView = UIView(frame: testFrame)


var button1 =  UIButton.buttonWithType(UIButtonType.Custom) as UIButton

button.frame = CGRectMake(0, 0, 40, 40) as CGRect

button.backgroundColor = UIColor.redColor()

button.setTitle("Button", forState: UIControlState.Normal)


var button2 =  UIButton.buttonWithType(UIButtonType.Custom) as UIButton

button.frame = CGRectMake(70, 0, 40, 40) as CGRect

button.backgroundColor = UIColor.redColor()

button.setTitle("Button", forState: UIControlState.Normal)

buttonView.addSubview(button1)

buttonView.addSubview(button2)

self.navigationItem.titleView = buttonView

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在iOS 8中使用UISearchController,其中UISearchBar位于导航栏中并具有范围按钮? - How do I use UISearchController in iOS 8 where the UISearchBar is in my navigation bar and has scope buttons? 如何在ios的导航栏中切换其他按钮? - How can I toggle extra buttons in the navigation bar for ios? 如何获得带按钮的滚动条? - How do i get the scrolling bar with buttons? 如何使用iOS自动布局将菜单中的按钮居中? - How do I use iOS auto layout to center buttons in a menu? 如何在iOS的导航项中显示后退栏按钮项? - How do I get the back bar button item to show up in my navigation item in iOS? 如何在Swift iOS的最后一个屏幕上获取导航栏? - How do I get Navigation bar on only the last screen in Swift iOS? 如何在导航栏中添加两个栏按钮? 遇到错误 - How can I add two bar buttons to a navigation bar? Getting an error 在Swift中,如何在没有导航栏的情况下制作快照? - How do I make a snapshot without the navigation bar in iOS with Swift? 如何在iOS应用中添加可编辑的导航栏? - How do I add an editable navigation bar to my iOS App? 如何在ios的quicklook视图顶部显示导航栏? - How do I show a navigation bar on top of quicklook view on ios?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM