我的appdelegate中有这个代码
UINavigationBar.appearance().backIndicatorImage = #imageLiteral(resourceName: "backarrow")
这段代码显示了如下内容
如何调整图像大小并更改其位置?
最佳答案
您好,您可以通过以下方式实现它:
var backImage = UIImage(named: "backarrow")
backImage = resizeImage(image: backImage!, newWidth: 40) //the width that you want for the back button image
UINavigationBar.appearance().backIndicatorImage = backImage
下面是图像大小调整函数
func resizeImage(image: UIImage, newWidth: CGFloat) -> UIImage? {
let scale = newWidth / image.size.width
let newHeight = image.size.height * scale
UIGraphicsBeginImageContext(CGSize(width: newWidth, height: newHeight))
image.draw(in: CGRect(x: 0, y: 0, width: newWidth, height: newHeight))
let newImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return newImage
}