[英]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.