iOS 设置导航条透明效果的实例代码

时间:2021-12-21 07:52:34

APP中很多界面都是这样的、从有不透明到透明,透明到不透明

以下代码即可实现该功能

?
1
2
3
4
5
6
7
8
9
10
11
12
//设置导航栏透明
 func setNavigationIsTranslucent(isTranslucent:Bool) {
   if isTranslucent == true {
     self.navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default)
     self.navigationController?.navigationBar.shadowImage = UIImage()
     navigationController?.navigationBar.barStyle = .black
   }else {
     navigationController?.navigationBar.setBackgroundImage(UIImage(named: "nav_bg"), for: .default)
     navigationController?.navigationBar.shadowImage = UIImage()
     navigationController?.navigationBar.barStyle = .black
   }
 }

总结

以上所述是小编给大家介绍的iOS 设置导航条透明效果的实例代码,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对服务器之家网站的支持!

原文链接:https://blog.csdn.net/weixin_38921307/article/details/79754614