繁体   English   中英

如何在IOS 8中使UINavigationBar透明?

[英]How to make UINavigationBar Transparent in IOS 8?

我已经尝试了很多让UINavigationBar透明的东西。 但我没有成功。我设置的图像是透明的。 这是我的代码。 有帮助吗? 提前致谢。

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

尝试这个

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

我希望上面的代码有所帮助。

尝试添加此代码。 它在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]

使用此代码,您甚至不需要添加透明的UIImage 如果有帮助,请在这里更新。

谢谢大家。 问题是我在视图控制器中添加了这一行:

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

这就是代码无效的原因。 当我删除该行

self.edgesForExtendedLayout = UIRectEdgeNone;

代码有效。

@Sushil好像他有它。 在我的应用程序中,我使用

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

而不是alloc init ,是唯一的区别。

尝试这个

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

这适用于IOS 7和+

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM