重叠UINavbar左项

时间:2015-09-18 07:23:01

标签: swift uinavigationbar

在我的swift iOS 8项目中,我将后退按钮图像更改为后退箭头,并使用AppDelegate中的以下代码删除了后退项目文本,但仍然获得了重叠项目。

varchar

如何删除文字? enter image description here

1 个答案:

答案 0 :(得分:1)

再添加一行:

UIBarButtonItem.appearance().setBackButtonTitlePositionAdjustment(UIOffsetMake(0, -60), forBarMetrics: .Default)

通过这种方式使用自定义按钮为条形按钮设置图像的另一种方法是:

let button: UIButton = UIButton.buttonWithType(UIButtonType.Custom) as! UIButton
button.setImage(UIImage(named: "GoBack"), forState: UIControlState.Normal)
button.addTarget(self, action: "backButtonPressed:", forControlEvents: UIControlEvents.TouchUpInside)
button.frame = CGRectMake(0, 0, 53, 31)  // set this as per your need.

let barButton = UIBarButtonItem(customView: button)
self.navigationItem.leftBarButtonItem = barButton

它的助手方法:

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