我将图像设置为弹出视图的背景。根据图像尺寸,我需要将内容模式设置为宽高比填充,缩放以填充或宽高比调整。
private func setBackground() {
UIGraphicsBeginImageContext(self.popUpFormula.frame.size)
UIImage(named: "background")?.draw(in: self.popUpFormula.bounds)
if let image = UIGraphicsGetImageFromCurrentImageContext(){
UIGraphicsEndImageContext()
self.popUpFormula.backgroundColor = UIColor(patternImage: image)
}else{
UIGraphicsEndImageContext()
debugPrint("Image not available")
}
}
我该怎么做?