6

I have tried a lot to make UINavigationBar transparent. But I failed making it so.The image which I set was transparent. Here is my code . Any help ? Thanks in advance.

 [rootNavC.navigationBar setBackgroundImage:[UIImage imageNamed:@"NAV_BG_iphone.png"] forBarMetrics:UIBarMetricsDefault];
rootNavC.navigationBar.translucent = YES;
rootNavC.navigationBar.backgroundColor = [UIColor clearColor];
[[UINavigationBar appearance] setTitleTextAttributes:@{
                           UITextAttributeTextColor : [UIColor whiteColor],
                     UITextAttributeTextShadowColor : [UIColor clearColor],
                    UITextAttributeTextShadowOffset : [NSValue valueWithUIOffset:UIOffsetMake(0, 0)],
                                UITextAttributeFont : [UIFont fontWithName:@"pastel" size:20]
 }];
Mounika Vangala
  • 396
  • 2
  • 3
  • 14

6 Answers6

15

try this

   [self.navigationController.navigationBar setBackgroundImage:[UIImage new]
                         forBarMetrics:UIBarMetricsDefault];
    self.navigationController.navigationBar.shadowImage = [UIImage new];
    self.navigationController.navigationBar.translucent = YES;
    self.navigationController.view.backgroundColor = [UIColor clearColor];

I hope the above code helps.

Aruna kumari
  • 329
  • 1
  • 11
9

Try adding this code. It worked for me in iOS 8.

[self.navigationController.navigationBar setTranslucent:YES];
[self.navigationController.navigationBar setBackgroundImage:[[UIImage alloc] init] forBarMetrics:UIBarMetricsDefault];
self.navigationController.navigationBar.shadowImage = [[UIImage alloc] init];
self.navigationController.navigationBar.backgroundColor = [UIColor clearColor]

Using this code, you don't even need to add your transparent UIImage. Update here if it helps you.

Sushil Sharma
  • 2,321
  • 3
  • 29
  • 49
6

Thanks all. The thing is that I am adding this line in my view controller:

if (IS_OS_7_OR_LATER)
{
    self.edgesForExtendedLayout = UIRectEdgeNone;
    self.extendedLayoutIncludesOpaqueBars = NO;
    self.automaticallyAdjustsScrollViewInsets = NO;
}

that is why the code is not working. When I remove the line

self.edgesForExtendedLayout = UIRectEdgeNone;

the code works.

Pang
  • 9,564
  • 146
  • 81
  • 122
Mounika Vangala
  • 396
  • 2
  • 3
  • 14
2

@Sushil it seems like he has it. In my app, I use

[self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];

Instead of alloc init, is the only difference.

Kekoa
  • 27,892
  • 14
  • 72
  • 91
Ripwalk
  • 21
  • 1
  • You'll need to remove the extra opening bracket if you're using this. Can't edit it since it's only a single character. – Uzaak Feb 19 '16 at 13:54
1

try this

 [rootNavC.navigationBar setBackgroundImage:[UIImage imageNamed:@"NAV_BG_iphone.png"] forBarMetrics:UIBarMetricsDefault];
  rootNavC.navigationBar.translucent = YES;
  [[rootNavC.UINavigationBar appearance] setBarTintColor:[UIColor clearColor]];
   //rootNavC.navigationBar.backgroundColor = [UIColor clearColor];
    [[UINavigationBar appearance] setTitleTextAttributes:@{
                       UITextAttributeTextColor : [UIColor whiteColor],
                 UITextAttributeTextShadowColor : [UIColor clearColor],
                UITextAttributeTextShadowOffset : [NSValue valueWithUIOffset:UIOffsetMake(0, 0)],
                            UITextAttributeFont : [UIFont fontWithName:@"pastel" size:20]
   }];
Sheshnath
  • 3,293
  • 1
  • 32
  • 60
1

This works on IOS 7 and +

[self.navigationController.navigationBar setTranslucent:YES];
self.navigationController.navigationBar.shadowImage = [UIImage new];
self.navigationController.view.backgroundColor = [UIColor clearColor];
[self.navigationController.navigationBar setBackgroundImage:[[UIImage alloc] init] forBarMetrics:UIBarMetricsDefault];
self.navigationController.navigationBar.shadowImage = [[UIImage alloc] init];
self.navigationController.navigationBar.backgroundColor = [UIColor clearColor];
Damien Romito
  • 9,801
  • 13
  • 66
  • 84