当前位置: 首页 > 知识库问答 >
问题:

透明iOS导航栏

唐泳
2023-03-14

我正在创建一个应用程序,我在互联网上浏览,我想知道他们是如何使这个透明的UINavigationBar像这样:

我在appdelegate中添加了以下内容:

UINavigationBar.appearance().translucent = true

但这只会让它看起来像:

如何使导航栏像第一个图像一样透明?

共有3个答案

彭坚壁
2023-03-14

Swift 5仅适用于当前视图控制器

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)

    // Make the navigation bar background clear
    navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default)
    navigationController?.navigationBar.shadowImage = UIImage()
    navigationController?.navigationBar.isTranslucent = true
}

override func viewWillDisappear(_ animated: Bool) {
    super.viewWillDisappear(animated)

    // Restore the navigation bar to default
    navigationController?.navigationBar.setBackgroundImage(nil, for: .default)
    navigationController?.navigationBar.shadowImage = nil
}
丌官昊天
2023-03-14

这是我找到的最好的方法。您可以将其粘贴到appDelegate的didFinishLaunchingWithOptions方法中:

斯威夫特3/4

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    // Override point for customization after application launch.
    // Sets background to a blank/empty image
    UINavigationBar.appearance().setBackgroundImage(UIImage(), for: .default)
    // Sets shadow (line below the bar) to a blank image
    UINavigationBar.appearance().shadowImage = UIImage()
    // Sets the translucent background color
    UINavigationBar.appearance().backgroundColor = .clear
    // Set translucent. (Default value is already true, so this can be removed if desired.)
    UINavigationBar.appearance().isTranslucent = true
    return true
}

雨燕2.0

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    // Override point for customization after application launch.
    // Sets background to a blank/empty image
    UINavigationBar.appearance().setBackgroundImage(UIImage(), forBarMetrics: .Default)
    // Sets shadow (line below the bar) to a blank image
    UINavigationBar.appearance().shadowImage = UIImage()
    // Sets the translucent background color
    UINavigationBar.appearance().backgroundColor = UIColor(red: 0.0, green: 0.0, blue: 0.0, alpha: 0.0)
    // Set translucent. (Default value is already true, so this can be removed if desired.)
    UINavigationBar.appearance().translucent = true

    return true
}

来源:在iOS 8.1中使导航栏对下图透明

寿浩言
2023-03-14

您可以应用导航栏图像,如下所示为半透明。

目标C:

[self.navigationController.navigationBar setBackgroundImage:[UIImage new]
                     forBarMetrics:UIBarMetricsDefault]; //UIImageNamed:@"transparent.png"
self.navigationController.navigationBar.shadowImage = [UIImage new];////UIImageNamed:@"transparent.png"
self.navigationController.navigationBar.translucent = YES;
self.navigationController.view.backgroundColor = [UIColor clearColor];

Swift 3:

self.navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default) //UIImage.init(named: "transparent.png")
self.navigationController?.navigationBar.shadowImage = UIImage()
self.navigationController?.navigationBar.isTranslucent = true
self.navigationController?.view.backgroundColor = .clear
    
 类似资料:
  • 本文向大家介绍iOS轻松实现导航栏透明渐变,包括了iOS轻松实现导航栏透明渐变的使用技巧和注意事项,需要的朋友参考一下 首先我们来看下效果 一开始当我们什么只设置了一张图片作为它的头部视图的时候,它是这样的 1.首当其冲的,我们先得把导航栏弄透明 那么我们首先得知道,设置navigationBar的BackgroundColor为Clear是没用的,你可以试着设置它的clear,但是没用,原因一会

  • 本文向大家介绍iOS实现导航栏透明示例代码,包括了iOS实现导航栏透明示例代码的使用技巧和注意事项,需要的朋友参考一下 在最近一个项目中碰到这样一个场景,在被push进来的一个页面设置导航栏透明,且要求控制对tableview组的头视图进行悬停显示,nav随着tableview偏移量改变透明度,当然这样的需求确实不是什么难事,但是如果当前页面继续push一个不需要此类效果的页面,当在返回当前页面的

  • 我一直在Stack上寻找一些关于这个的指导,但是没有一个问题被问到这么深,答案也没有更新到最新的Swift版本,甚至没有更新到最新的Swift版本。 这是我所拥有的: 带有两个栏项目的导航控制器: 我的目标是:使导航根视图控制器的导航栏透明(但按钮和标题仍然可见),而不是子导航——没有奇怪的细微差别,比如之前的彩色闪光,或切断导航栏(参见gif) 我尝试过的事情: 在<代码>视图将出现(u动画:B

  • 我想要这样的东西: 我不知道如何实现…任何帮助!

  • 我一直在尝试为我的应用程序获得一个透明的导航栏,但我已经尝试到目前为止,并没有给我的结果,我正在寻找。 作为一个参考示例,下面是“Play Store”导航栏的外观: 注意,它是一个黑暗但透明的颜色。 我在应用程序中尝试了以下内容: 我已经将我的主题和单个支架的背景颜色设置为深色,但我的导航栏仍然是白色的,如下图所示: 正如你在上图中看到的,状态栏接受它的透明颜色,并尊重应用背景,但导航栏不接受。

  • 本文向大家介绍iOS 设置导航条透明效果的实例代码,包括了iOS 设置导航条透明效果的实例代码的使用技巧和注意事项,需要的朋友参考一下 APP中很多界面都是这样的、从有不透明到透明,透明到不透明 以下代码即可实现该功能 总结 以上所述是小编给大家介绍的iOS 设置导航条透明效果的实例代码,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对呐喊教程网站的支持