Black background on transparent UITabBar

前端 未结 4 1070
有刺的猬
有刺的猬 2021-02-01 07:12

I am trying to make a blurred background the UITabBar for my UITabViewController, and the idea is to have it be blurred and transparent so that the vie

4条回答
  •  时光取名叫无心
    2021-02-01 07:41

    I found a prefect solution, you only need to subclass UITabBar and then do the following actions to clean that annoying views

    class MainTabBar: UITabBar {
        var cleanDone = false
    
        override func layoutSubviews() {
            super.layoutSubviews()
            self.deleteUnusedViews()
        }
    
        func deleteUnusedViews() {
            if !self.cleanDone {
                var removeCount = 0
                for (_, eachView) in (self.subviews.enumerate()) {
                    if NSStringFromClass(eachView.classForCoder).rangeOfString("_UITabBarBackgroundView") != nil {
                        eachView.removeFromSuperview()
                        removeCount += 1
                    }
                    if NSStringFromClass(eachView.classForCoder).rangeOfString("UIImageView") != nil {
                        eachView.removeFromSuperview()
                        removeCount += 1
                    }
                    if removeCount == 2 {
                        self.cleanDone = true
                        break
                    }
                }
            }
        }
    }
    

提交回复
热议问题