// 把颜色转成图片 

 

 func imageFromColor(color: UIColor, viewSize: CGSize) -> UIImage{

        let rect: CGRect = CGRect(x: 0, y: 0, width: viewSize.width, height: viewSize.height)

        UIGraphicsBeginImageContext(rect.size)

        let context: CGContext = UIGraphicsGetCurrentContext()!

        context.setFillColor(color.cgColor)

        context.fill(rect)

        

        let image = UIGraphicsGetImageFromCurrentImageContext()

        UIGraphicsGetCurrentContext()

        return image!

    }

 

 

// 调用方法替换导航栏背景色

        navigationController?.navigationBar.setBackgroundImage(imageFromColor(color: UIColor.white.withAlphaComponent(0), viewSize: CGSize(width: kScreenW, height: 1)), for: UIBarPosition.any, barMetrics: UIBarMetrics.default)

        

        navigationController?.navigationBar.shadowImage = UIImage()

相关文章:

  • 2022-03-06
  • 2022-12-23
  • 2021-07-23
  • 2021-12-10
  • 2022-12-23
  • 2021-11-01
  • 2021-07-13
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-12-14
  • 2021-05-14
  • 2021-09-09
  • 2022-12-23
相关资源
相似解决方案