0
votes

On viewwillAppear I am changing the navigationbar background color. I am trying to set a view with frame (0,53,width,height). On the first go it is showing proper and it's taking 53 after navigationbar's height but when I change the theme and come to that controller it's taking 53 from 0. So it's hiding behind the navigation bar.

I am writing following code in viewwillappear.

if(oldTheme)
{
self.navigationController?.navigationBar.setBackgroundImage(UIImage(named:"bar.png"), for: .default)
}
else {
self.navigationController?.navigationBar.setBackgroundImage(UIImage(named:"bar2.png"), for: .default)
}

Please advice.

THanks in Advance.

1

1 Answers

0
votes

When you change backgroundColor property you call layoutSubviews and eventually cause everything to layout again. If you set your view frame programmatically you should do that in in layoutSubviews of the view or in viewWillLayoutSubviews of a viewController