Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIBarButtonItem font weight changes after push pop of navigation stack

I have a UIBarButtonItem, "Done" - created in storyboard IB for ViewController A.

ViewController A is the root View Controller of the navigation stack.

If I push a View Controller B onto the navigation stack and then pop it again. the font weight of the Done button changes.

Start Scenario - A B pushed onto stack B popped from the stack

The font colour of the Done button is applied in A.viewWillAppear(..) and looks pretty much like

doneButton.tintColor = [CMPThemes navigationBarItemColour]; // it's a blue
  • I have stripped all appearance proxy code from the app (because there are more than one style of navigation bars/buttons/titles appear in the app) so I'm not looking for a fix that can only be done via the appearance proxy...

  • I have checked in the debug view hierarchy that the Done button is the same instance before and after the transitions

  • I have tried to re-apply the tint colour after the pop

  • I don't apply a font weight anywhere in the process

  • Also, to my eye, the font and font size seem to be unchanged during the process.

In ViewController A

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    ...
    self.navigationController?.pushViewController(vcB, animated: true)
    ...

In ViewController B

viewDidLoad() {
    ...
    let backButton = UIBarButtonItem(image: UIImage(named: "arrowLeft"), style: .plain, target: self, action: #selector(goBack))
    backButton.tintColor = CMPThemes.popoverNavigationBarItemColour()
    self.navigationItem.leftBarButtonItem  = backButton
}

The storyboard looks like: (I've added the A and B to the image to maintain clarity).

enter image description here

If someone recognises the problem and can point me in the right direction for a fix that would be great!

like image 311
Damo Avatar asked Nov 15 '17 17:11

Damo


1 Answers

I found the problem. The applied tint colour is not the issue. I think, Initially when it was loading the done button from the storyboard, the doneButton Style was equals .done and later when you are popping to ViewControllerA, somehow the style getting changed to .plan, so I think setting the style below the tint should fix the issue.

Try updating the viewWillAppear method in ViewControllerA with following code:

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)
    doneButton.tintColor = [CMPThemes navigationBarItemColour]; // it's a blue
    doneButton.style = .done
}

Hope it helps!

like image 73
Bhavin Kansagara Avatar answered Nov 13 '22 12:11

Bhavin Kansagara