I am trying to left align back button i.e remove the space on the left of the back arrow . Using a custom back button .
我试图左后对齐按钮,即删除后箭头左侧的空格。使用自定义后退按钮。
let backButton = UIBarButtonItem(image: UIImage(named: "arrow03"), style: .Plain, target: self, action: "back")
self.navigationController?.navigationBar.tintColor = UIColor.clearColor()
self.navigationItem.backBarButtonItem = backButton
Tried to use negative width for the button as suggested in the below SO link but it didnt work. How to Edit Empty Spaces of Left, Right UIBarButtonItem in UINavigationBar [iOS 7]
尝试使用负宽度按钮,如下面的SO链接所示,但它没有工作。如何在UINavigationBar [iOS 7]中编辑左,右UIBarButtonItem的空格
Image
Please help.
1 个解决方案
#1
6
Refer below code to implement back button on left alignment.
请参阅下面的代码以实现左对齐的后退按钮。
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
Note - Make sure your image has to be plain ( transparent ) background.
注意 - 确保您的图像必须是纯色(透明)背景。
func backButtonPressed(btn : UIButton) {
self.navigationController?.popViewControllerAnimated(true)
}
#1
6
Refer below code to implement back button on left alignment.
请参阅下面的代码以实现左对齐的后退按钮。
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
Note - Make sure your image has to be plain ( transparent ) background.
注意 - 确保您的图像必须是纯色(透明)背景。
func backButtonPressed(btn : UIButton) {
self.navigationController?.popViewControllerAnimated(true)
}