swift5.0消除導航欄Nav與標籤欄tab下劃線

分系統版本,有點區別

 ///消除導航欄下劃線
    func clearNavigationBarLine() {
        self.navigationController?.navigationBar.setBackgroundImage(UIImage(), for: UIBarMetrics.default)
        self.navigationController?.navigationBar.shadowImage = UIImage()
    }
    
    ///消除標籤欄下劃線
    func clearTabBarLine() {
        let image_w = creatColorImage(.white)
        if #available(iOS 13.0, *) {
            let appearance = UITabBarAppearance()
            appearance.backgroundImage = image_w
            appearance.shadowImage = image_w
            self.tabBarController?.tabBar.standardAppearance = appearance
        } else {
            self.tabBarController?.tabBar.backgroundImage = image_w
            self.tabBarController?.tabBar.shadowImage = image_w
        }
    }
    ///用顏色創建一張圖片
    func creatColorImage(_ color:UIColor,_ ARect:CGRect = CGRect.init(x: 0, y: 0, width: 1, height: 1)) -> UIImage {
        let rect = ARect
        UIGraphicsBeginImageContext(rect.size)
        let context = UIGraphicsGetCurrentContext()
        context?.setFillColor(color.cgColor)
        context?.fill(rect)
        let image = UIGraphicsGetImageFromCurrentImageContext()
        UIGraphicsEndImageContext()
        return image!
    }
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章