zoukankan      html  css  js  c++  java
  • swift把颜色转成图片

    // 把颜色转成图片 

     

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

            let rect: CGRect = CGRect(x: 0, y: 0, 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( kScreenW, height: 1)), for: UIBarPosition.any, barMetrics: UIBarMetrics.default)

            

            navigationController?.navigationBar.shadowImage = UIImage()

  • 相关阅读:
    随机生成300道四则运算
    练习
    电梯演说模板练习
    敏捷开发
    团队模式
    思考
    build to win 观后感
    四则运算
    Code review
    Mutual review
  • 原文地址:https://www.cnblogs.com/supersr/p/6743410.html
Copyright © 2011-2022 走看看