【问题标题】:iOS 13 Tab Bar Layer attribute is missing swiftiOS 13 选项卡栏图层属性缺少 swift
【发布时间】:2020-09-12 00:08:14
【问题描述】:

我在初始版本的标签栏上添加了阴影层,但是在iOS 13上我们必须使用没有层属性的外观,现在如何添加阴影。

顶部的阴影如下图。

if #available(iOS 13, *) {
            let appearance = self.self.tabBarController?.tabBar.standardAppearance.copy()
            appearance?.backgroundImage = UIImage()
            appearance?.shadowImage = UIImage()
            appearance?.shadowColor = .clear
            //appearance?.layer this is missing now
            if let appearance = appearance{
                self.tabBarController?.tabBar.standardAppearance = appearance
            }

        } else {
        self.tabBarController?.tabBar.shadowImage = UIImage()
        self.tabBarController?.tabBar.backgroundImage = UIImage()
        self.tabBarController?.tabBar.layer.shadowOpacity = 0.0
        self.tabBarController?.tabBar.layer.borderWidth = 0.0
        self.tabBarController?.tabBar.clipsToBounds = true
        self.tabBarController?.tabBar.layer.applySketchShadow(color: UIColor(red: 15/255, green: 54/255, blue: 136/255, alpha: 1.0), alpha: 0.1, x: 0, y: 0, blur: 25, spread: 0)
        self.tabBarController?.tabBar.clipsToBounds = false
        }

【问题讨论】:

  • 你使用过 configureWithTransparentBackground.. 你想让你的标签栏透明吗??

标签: ios swift tabbar


【解决方案1】:

UIBarAppearance 具有 shadowImageshadowColor 属性。根据需要设置它们。现在您将它们设置为具有 no 阴影。 configureWithTransparentBackground 也表示 no 阴影。所以你要移除阴影,然后询问阴影在哪里。

【讨论】:

  • 我想要一个不在导航栏顶部的阴影,我的问题是关于图层属性
【解决方案2】:

在您的 UITabBarController 类中尝试以下代码

 override func viewDidLoad() {
        super.viewDidLoad()

      if #available(iOS 13, *) {
            let appearance = self.tabBar.standardAppearance.copy()
            appearance.backgroundImage = UIImage()
            appearance.shadowImage = UIImage()
            self.tabBar.standardAppearance = appearance
        } else {
            self.tabBar.shadowImage = UIImage()
            self.tabBar.backgroundImage = UIImage()
        }

        //Change These values according to your requirement. This will work for all iOS versions
        self.tabBar.layer.shadowColor = UIColor.lightGray.cgColor
        self.tabBar.layer.shadowOpacity = 0.3
        self.tabBar.layer.shadowRadius = 5
}

【讨论】:

【解决方案3】:

Set clipsToBounds False 将为您带来神奇的效果。

//**self.tabBarController?.tabBar.clipsToBounds = false**

if #available(iOS 13, *) {
    let appearance = self.self.tabBarController?.tabBar.standardAppearance.copy()
    appearance?.backgroundImage = UIImage()
    appearance?.shadowImage = UIImage()
    appearance?.configureWithTransparentBackground()
    if let appearance = appearance{
        self.tabBarController?.tabBar.standardAppearance = appearance
    }

} else {
self.tabBarController?.tabBar.shadowImage = UIImage()
self.tabBarController?.tabBar.backgroundImage = UIImage()
self.tabBarController?.tabBar.clipsToBounds = false

}
self.tabBarController?.tabBar.clipsToBounds = false
self.tabBarController?.tabBar.layer.shadowOpacity = 0.0
self.tabBarController?.tabBar.layer.borderWidth = 0.0
self.tabBarController?.tabBar.layer.applySketchShadow(color: UIColor(red: 15/255, green: 54/255, blue: 136/255, alpha: 1.0), alpha: 0.1, x: 0, y: 0, blur: 25, spread: 0)

【讨论】:

    猜你喜欢
    • 2021-06-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-27
    • 2013-10-24
    • 1970-01-01
    • 2019-06-24
    • 1970-01-01
    相关资源
    最近更新 更多