0

This is the code I am using in viewWillAppear:

UINavigationBar *navbar = [[UINavigationBar alloc]initWithFrame:CGRectMake(0, 0, 1420, 50)];
//do something like background color, title, etc you self
[[UINavigationBar appearance] setBarTintColor:[UIColor underPageBackgroundColor]];
self.navigationController.navigationBar.translucent = NO;
[self.view addSubview:navbar];

UINavigationItem *item = [[UINavigationItem alloc]
                          init];
navbar.items= @[item];
UIBarButtonItem *backButton = [[UIBarButtonItem alloc]
                               initWithTitle:@"Back"
                               style:UIBarButtonItemStylePlain
                               target:self
                               action:@selector(backBtnClicked:)];
item.leftBarButtonItem = backButton;

I want to remove the shadowImage. The line underneath the nav bar but ONLY in one view controller. How do I do this?

enter image description here

I've already tried this but it changes all view controllers, to be like, invisible:

[[UINavigationBar appearance] setBackgroundImage: [UIImage new]  
                               forBarMetrics: UIBarMetricsDefault];

[UINavigationBar appearance].shadowImage = [UIImage new];

Any help would be greatly appreciated!

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Creagen
  • 478
  • 5
  • 17

1 Answers1

0

I had an issue with white space appearing under my nav bar. Is this what you mean by a line? I solved it within xCode's Interface Builder by:

  1. Selecting the view controller in the storyboard
  2. Going to the attributes section of the right toolbar
  3. Check the box "Under Opaque Bars" in the "Extend Edges" section.

I also added the following code in my viewDidLoad method:

self.automaticallyAdjustsScrollViewInsets = NO;
Tony
  • 2,890
  • 1
  • 24
  • 35
  • I just made sure to check "Under Opaque Bars" and I was hoping it would be my solution but it didn't seem to work :/ – Creagen May 24 '17 at 22:54
  • @Creagen Have you tried the code I added to the answer? – Tony May 25 '17 at 00:42
  • I tried the code and that does not seem to work either. I deleted a few view controllers in my storyboard and realized the view controller is being called pragmatically like this NSString *path = [[NSBundle mainBundle] pathForResource:@"PalayeRoyale2" ofType:@"pdf"]; PageViewController *page = [[PageViewController alloc] initWithPDFAtPath:path]; [self presentViewController:page animated:YES completion:NULL]; – Creagen May 25 '17 at 00:56
  • Is there any way to pragmatically do "Under Opaque Bars"? – Creagen May 25 '17 at 00:57
  • @Creagen Maybe check out this question: https://stackoverflow.com/questions/18875322/how-to-set-uiviewcontroller-extend-edges-properties. I really understand your frustration with this. I've fought this issue more times than I can count. – Tony May 25 '17 at 01:02
  • I know :/ I've been messing around with self.extendedLayoutIncludesOpaqueBars = YES; and I can't get it to work either. :( – Creagen May 25 '17 at 01:06
  • @Creagen Try adding an empty label as the first element in your view controllers hierarchy. It seems kinda weird but thats worked for me in the past. – Tony May 25 '17 at 01:08