Swift 如何让 UITabBar 变得模糊
How to make UITabBar blurry, in Swift
我正在尝试使 UITabBar 看起来模糊。
I am trying to make something like this in this image
但我的观点现在看起来像这样
This is my view for tabbar
我在 UITabbarController 中尝试了这段代码 -
Code:
class TabBarViewController: UITabBarController {
override func viewDidLoad() {
super.viewDidLoad()
configureTabbar()
}
func configureTabbar(){
let blurEffect = UIBlurEffect(style: .dark)
let vibrancyEffect = UIVibrancyEffect(blurEffect: blurEffect)
let vibrancyView = UIVisualEffectView()
vibrancyView.frame = tabBar.bounds
vibrancyView.autoresizingMask = .flexibleWidth
vibrancyView.effect = vibrancyEffect
tabBar.insertSubview(vibrancyView, at: 0)
tabBar.isTranslucent = true
tabBar.backgroundImage = UIImage()
tabBar.backgroundColor = .clear
tabBar.barStyle = UIBarStyle.black
tabBar.barTintColor = UIColor.clear
}
UINavigationBar
、UITabBar
和 UIToolbar
等系统栏默认是半透明的,您不需要添加任何额外的东西来获得这种效果。
您只需要确保您的视图在系统栏下扩展它的内容。您可以转到情节提要并确保为您计划在其上看到此效果的 UIViewController
检查 Extend Edges - Under Bottom Bars
。
我正在尝试使 UITabBar 看起来模糊。 I am trying to make something like this in this image 但我的观点现在看起来像这样 This is my view for tabbar
我在 UITabbarController 中尝试了这段代码 -
Code:
class TabBarViewController: UITabBarController {
override func viewDidLoad() {
super.viewDidLoad()
configureTabbar()
}
func configureTabbar(){
let blurEffect = UIBlurEffect(style: .dark)
let vibrancyEffect = UIVibrancyEffect(blurEffect: blurEffect)
let vibrancyView = UIVisualEffectView()
vibrancyView.frame = tabBar.bounds
vibrancyView.autoresizingMask = .flexibleWidth
vibrancyView.effect = vibrancyEffect
tabBar.insertSubview(vibrancyView, at: 0)
tabBar.isTranslucent = true
tabBar.backgroundImage = UIImage()
tabBar.backgroundColor = .clear
tabBar.barStyle = UIBarStyle.black
tabBar.barTintColor = UIColor.clear
}
UINavigationBar
、UITabBar
和 UIToolbar
等系统栏默认是半透明的,您不需要添加任何额外的东西来获得这种效果。
您只需要确保您的视图在系统栏下扩展它的内容。您可以转到情节提要并确保为您计划在其上看到此效果的 UIViewController
检查 Extend Edges - Under Bottom Bars
。