How to make UINavigationBar Transparent in IOS 8?

◇◆丶佛笑我妖孽 提交于 2019-11-30 20:37:18

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.

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.

Mounika Vangala

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.

Ripwalk

@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.

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]
   }];

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];
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!