Remove text from Back button keeping the icon

前端 未结 29 2705
栀梦
栀梦 2020-11-28 23:26

I want to remove the text from the back button, but I want to keep the icon. I have tried

let backButton = UIBarButtonItem(title: \"\", style: UIBarButtonIt         


        
29条回答
  •  情书的邮戳
    2020-11-29 00:04

    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) {
    
        // Your code
    }
    

提交回复
热议问题