Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Navigation controller background image repeat it self in ios 11 using xcode 9

I had tried following code to set background image of UINavigationBar. It was working fine before Xcode 9 but in Xcode 9 image are not set properly.

UIImage *image = [UIImage imageNamed:@"headr_bg"];
[self.navigationController.navigationBar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];

Xcode 9 image 1

Xcode 9 image 2

[before Xcode 9]

like image 229
Jaydeep Patel Avatar asked Jan 30 '26 20:01

Jaydeep Patel


1 Answers

may be its not perfect solution & but i had old project in that i had fixed it by below code. Just updated navigation bar position and navigation view frame for ios version > 11.

CGRect navbarFrame = self.navigationController.navigationBar.frame;
CGRect navFrame = self.navigationController.view.frame;
navbarFrame.size.height = 44;
navFrame.origin.y = 20;
self.navigationController.navigationBar.frame = navbarFrame;
self.navigationController.view.frame = navFrame;
like image 122
Jaydeep Patel Avatar answered Feb 01 '26 11:02

Jaydeep Patel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!