gpt4 book ai didi

ios - UINavigationItem 透明度 iOS

转载 作者:行者123 更新时间:2023-11-28 08:05:19 26 4
gpt4 key购买 nike

我在我的应用程序中使用导航 Controller 。对于我的 View Controller ,我使用了 UINavigationItem 并添加了 UIBarButton 项和标题 View 。

我需要为我的导航栏实现透明度。

我添加了以下代码。

    self.navigationController?.navigationBar.isTranslucent = true
let navAlpha = 0.7// Your appropriate calculation
let image = UIImage.imageFromColor(color: UIColor.red.withAlphaComponent(CGFloat(navAlpha)))
self.navigationController?.navigationBar.setBackgroundImage(image, for: UIBarMetrics.default)
self.navigationController?.navigationBar.barStyle = .default

这个的输出是:

enter image description here如何使包括 UINavigationItem 在内的整个导航栏透明?

最佳答案

在第一个 View Controller 中添加此代码。

    var navigationBarAppearace = UINavigationBar.appearance()
navigationBarAppearace.isTranslucent = true
let navAlpha = 0.7// Your appropriate calculation
let image = UIImage.imageFromColor(color:
UIColor.red.withAlphaComponent(CGFloat(navAlpha)))
navigationBarAppearace.setBackgroundImage(image, for: UIBarMetrics.default)
navigationBarAppearace.barStyle = .default

关于ios - UINavigationItem 透明度 iOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45342328/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com