-1

I'm using this code to display a custom button as leftButtonItem:

    let button = UIButton(type: .system)
    button.setTitleColor(.white, for: .normal)
    button.setImage(UIImage(named: "Back"), for: UIControlState.normal)
    button.addTarget(self, action: #selector (DetailExperienceTVC.back), for: .touchUpInside)
    button.setTitle(DataManager.shared.arrayMenuTop[DataManager.shared.indexTitle].title, for: .normal)
    button.titleLabel?.font = ColorManager.shared.generalFont30

    button.sizeToFit()

    button.titleEdgeInsets = UIEdgeInsetsMake((self.navigationController!.navigationBar.frame.height) / 4, 10, 0, 0)

    navigationItem.leftBarButtonItem = UIBarButtonItem(customView: button)

but this is what I get wrong size button, my question is how can I distanziate the text from the image without cropping it? Thanks in advance!

1 Answers1

-1

Here's the fix:

 button.titleLabel?.adjustsFontSizeToFitWidth = true