后退button左alignmentIOS 9

我正在尝试左alignmentbutton, 删除后退箭头左侧的空间。 使用自定义后退button。

let backButton = UIBarButtonItem(image: UIImage(named: "arrow03"), style: .Plain, target: self, action: "back") self.navigationController?.navigationBar.tintColor = UIColor.clearColor() self.navigationItem.backBarButtonItem = backButton 

试图使用button的负面宽度build议在下面的链接,但它没有工作。 如何在UINavigationBar [iOS 7]中编辑左侧,右侧UIBarButtonItem的空白空间

图片

在这里输入图像说明

View post on imgur.com

请帮忙。

请参阅下面的代码来实现左alignment上的后退button。

 let button: UIButton = UIButton (type: UIButtonType.Custom) button.setImage(UIImage(named: "imageName"), forState: UIControlState.Normal) button.addTarget(self, action: "backButtonPressed:", forControlEvents: UIControlEvents.TouchUpInside) button.frame = CGRectMake(0, 0, 30, 30) let barButton = UIBarButtonItem(customView: button) self.navigationItem.leftBarButtonItem = barButton 

注意 –确保您的图像必须是简单(透明)的背景。

 func backButtonPressed(btn : UIButton) { self.navigationController?.popViewControllerAnimated(true) }