首页 > 其他 > 详细

给导航条设置成颜色的背景图像 : UIGraphicsBeginImageContext ...

时间:2017-04-23 23:07:50      阅读:383      评论:0      收藏:0      [点我收藏+]

self.navigationBar.setBackgroundImage(createImageWithColor(UIColor.clear), for: .default)


//////////////////////


func createImageWithColor(_ color:UIColor) -> UIImage{

    return createImageWithColor(color, size: CGSize(width: 1, height: 1))

}

func createImageWithColor(_ color:UIColor,size:CGSize) -> UIImage {

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

    UIGraphicsBeginImageContext(rect.size);

    let context = UIGraphicsGetCurrentContext();

    context?.setFillColor(color.cgColor);

    context?.fill(rect);

    

    let theImage = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    return theImage!;

}



给导航条设置成颜色的背景图像 : UIGraphicsBeginImageContext ...

原文:http://9507270.blog.51cto.com/9497270/1918611

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!