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()

  • 相关阅读:
    2.搭建第一个http服务:三层架构
    1.基础入门
    MyISAM和InnoDB索引区别
    分区
    事务的四大特性
    事务
    String
    自己写native方法
    序列化和反序列化
    反射
  • 原文地址:https://www.cnblogs.com/supersr/p/6743410.html
Copyright © 2011-2022 走看看