0
votes

I set setTitleTextAttributes for barButtonItem, UIColor, Custom Font. When I tapped on barButton, during that time when I hold barButton, font changes to the system one, after I let go barButton it return to the custom font.I don't use tintColor settings. Why this happen?

May anyone help me?

This is how I set properties:

@IBOutlet weak var saveBarButton: UIBarButtonItem! { 
    didSet {
        saveBarButton.title = "SAVE"
        saveBarButton.setTitleTextAttributes([NSAttributedString.Key.font:
        UIFont.textStyle5], for: .normal)
    } 
}

I use custom UIFont. Thanks in advance.

2
Maybe you paste some code about how you are setting the values. You should try to set values for both the normal and selected states.AjinkyaSharma

2 Answers

1
votes

You need to set the same font for the highlighted state as well:

saveBarButton.setTitleTextAttributes([NSAttributedString.Key.font: UIFont.textStyle5], for: .highlighted) 
0
votes

In iOS 15 you can use this line of code:

saveBarButton.configuration?.attributedTitle?.font = UIFont.textStyle5