去掉tabBar黑线, iOS13

iOS 13 之前, 去掉黑线:设置UITarBar的 backgroundImage 和 shadowImage即可:

        tabbar.backgroundImage = UIImage(color: UIColor.clear)
        tabbar.shadowImage = UIImage(color: UIColor.clear)

iOS13之后不好使了,改用下面的方法:

        let appearance = tabbar.standardAppearance.copy()
        appearance.backgroundImage = UIImage(color: UIColor.clear)
        appearance.shadowImage = UIImage(color: UIColor.clear)
        tabbar.standardAppearance = appearance

所以兼容代码如下:

    if #available(iOS 13, *) {
        let appearance = tabbar.standardAppearance.copy()
        appearance.backgroundImage = UIImage(color: UIColor.clear)
        appearance.shadowImage = UIImage(color: UIColor.clear)
        tabbar.standardAppearance = appearance
    } else {
        tabbar.backgroundImage = UIImage(color: UIColor.clear)
        tabbar.shadowImage = UIImage(color: UIColor.clear)
    }

你可能感兴趣的:(ios基础,iOS13兼容,UITabar,去黑线)