我正在尝试为导航控制器的共享扩展设置背景图像。 问题是我的背景图片是透明的,但它在导航控制器中不显示透明。
这是我的代码:
func getImageWithColor(color: UIColor, size: CGSize) -> UIImage {
let rect = CGRect(x: 0, y: 0, width: size.width, height: size.height)
UIGraphicsBeginImageContextWithOptions(size, false, 0)
// color.setFill()
// UIRectFill(rect)
if let img = UIImage(named: "images.jpg") {
img.draw(in: CGRect(x: (size.width-size.height) / 2, y: 20, width: 30, height: 30))
}
let image: UIImage = UIGraphicsGetImageFromCurrentImageContext()!
UIGraphicsEndImageContext()
return image
}
// Calling viewDidLoad
self.navigationController?.navigationBar.setBackgroundImage(getImageWithColor(color: UIColor.darkGray, size: navSize), for: .default)