美文网首页
57.TabBar和NVBar的背景和阴影颜色设置

57.TabBar和NVBar的背景和阴影颜色设置

作者: noonez | 来源:发表于2018-09-21 16:31 被阅读12次
    class CustomTabBarController: UITabBarController {
    
        override func viewDidLoad() {
            super.viewDidLoad()
    
            // Do any additional setup after loading the view.
            
            //设置tabbar的背景和阴影图片
            tabBar.backgroundImage = UIImage()
            tabBar.shadowImage = drawShadowLine(height: 1, color: UIColor.green)
        }
        
        
        func drawShadowLine(height:CGFloat, color:UIColor)->UIImage? {
            UIGraphicsBeginImageContextWithOptions(CGSize(width: UIScreen.main.bounds.width, height: height), false, UIScreen.main.scale)
            if let context = UIGraphicsGetCurrentContext() {
                context.setFillColor(color.cgColor)
                context.fill(CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: height))
                let image = UIGraphicsGetImageFromCurrentImageContext()
                UIGraphicsEndImageContext()
                return image
            }
            return nil
        }
    }
    
    class CustomNVController: UINavigationController {
    
        override func viewDidLoad() {
            super.viewDidLoad()
    
            // Do any additional setup after loading the view.
            
            navigationBar.setBackgroundImage(UIImage(), for: .default)
            navigationBar.shadowImage = drawShadowLine(height: 1, color: UIColor.red)
        }
        
        func drawShadowLine(height:CGFloat, color:UIColor)->UIImage? {
            UIGraphicsBeginImageContextWithOptions(CGSize(width: UIScreen.main.bounds.width, height: height), false, UIScreen.main.scale)
            if let context = UIGraphicsGetCurrentContext() {
                context.setFillColor(color.cgColor)
                context.fill(CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: height))
                let image = UIGraphicsGetImageFromCurrentImageContext()
                UIGraphicsEndImageContext()
                return image
            }
            return nil
        }
    
    }
    

    相关文章

      网友评论

          本文标题:57.TabBar和NVBar的背景和阴影颜色设置

          本文链接:https://www.haomeiwen.com/subject/kjqznftx.html