Swift - navigation controller remove arrow button

I have an app in swift where the view controllers are embedded in the navigation controller, now on the second and third view controllers, there is a blue arrow pointing backwards on the back button (which is the default). I tried to remove this, but when I want to have an image, the image gets all bad. Does anyone know how you are going to shoot the arrow with the back button and replace it with an image? Many thanks!

+3


source to share


1 answer


Use this ....

Set text:

let backBtn = UIBarButtonItem(title: "Back", style: UIBarButtonItemStyle.Plain, target: self, action: "BtnTapBack:")
navigationItem.leftBarButtonItem = backBtn
navigationItem.leftBarButtonItem?.setTitleTextAttributes([NSFontAttributeName: UIFont(name: "YourFontName", size: 20)!], forState: UIControlState.Normal)

      

Install Image:



let image = UIImage(named:"YourImageName") as UIImage!
var btnBack:UIButton = UIButton.buttonWithType(UIButtonType.Custom) as! UIButton
btnBack.addTarget(self, action: "BtnTapBack:", forControlEvents: UIControlEvents.TouchUpInside)
btnBack.setImage(image, forState: UIControlState.Normal)
btnBack.setTitleColor(UIColor.blueColor(), forState: UIControlState.Normal)
btnBack.sizeToFit()
var myCustomBackButtonItem:UIBarButtonItem = UIBarButtonItem(customView: btnBack)
self.navigationItem.leftBarButtonItem  = myCustomBackButtonItem

      

Action go to previous view manager

@IBAction func BtnTapBack(sender: UIButton) {
        navigationController?.popViewControllerAnimated(true)
}

      

+5


source







All Articles