首页 > 代码库 > 给导航条设置成颜色的背景图像 : UIGraphicsBeginImageContext ...
给导航条设置成颜色的背景图像 : UIGraphicsBeginImageContext ...
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 ...