2017-07-17 69 views
0

我尝试在我的导航栏移至右边的按钮可以用按钮对齐在表视图右边这里是目前看起来像looks like我怎么能在UINavigation酒吧将按钮移到右边

我犯了这样的一个按钮:

let allButton = UIButton(frame: CGRect(x: 0, y: 0, width: 20, height: 20)) 
    allButton.layer.borderColor = Constants.AppColor.cgColor 
    allButton.layer.borderWidth = 1 
    allButton.layer.backgroundColor = UIColor.white.cgColor 
    allButton.addTarget(self, action: #selector(selectAllContacts), for: .touchUpInside) 
    allButton.layer.cornerRadius = 10 

和IM将它添加到我的导航栏是这样的:

 navigationItem.rightBarButtonItems = [UIBarButtonItem(customView: allButton), importButton] 

我已经尝试添加图像的插图,内容的镶边, nd它不起作用。

任何想法我还可以尝试什么?

回答

0

这会吗?

navigationItem.rightBarButtonItem =的UIBarButtonItem( 标题: “菜单>”, 风格:.plain, 目标:自我, 行动:#selector(rightNavTap) )

+0

我不认为这会解决我的问题,我只需要将我的按钮向右移动几个像素 – RickS

0

我能够解决这个加入

let negativeSpacer:UIBarButtonItem = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.fixedSpace, target: nil, action: nil) 
    negativeSpacer.width = -10 

和追加,为我的按钮的阵列

 navigationItem.rightBarButtonItems = [negativeSpacer, UIBarButtonItem(customView: allButton), importButton] 

如果有人找到更好的解决方案,请告诉我。