Saturday, November 21, 2026
HomeiOS Developmentswift - Since ios 16 my operate for redrawing photographs shouldn't be...

swift – Since ios 16 my operate for redrawing photographs shouldn’t be working correctly

[ad_1]

That is my operate as extension UIImage:

func scaledWithMaxWidthOrHeightValue(worth: CGFloat, spacing: CGFloat = 0, backgroundColor: UIColor = .clear, line: Bool = false, printing: Bool = false) -> UIImage? {
    
    let width = self.dimension.width
    let top = self.dimension.top
    
    if width < worth && top < worth {
        return self
    }
    
    let ratio = width/top
    
    var newWidth = worth
    var newHeight = worth
    
    if ratio > 1 {
        newWidth = min(width, worth)
        newHeight = top * (newWidth/width)
    } else {
        newHeight = min(top, worth)
        newWidth = width * (newHeight/top)
    }
    
    let rangeWidth = newWidth + spacing * 2
    let rangeHeight = newHeight + spacing * 2
    UIGraphicsBeginImageContextWithOptions(CGSize(width: rangeWidth, top: rangeHeight), false, 0)
    let ctx = UIGraphicsGetCurrentContext()
    backgroundColor.setFill()
    ctx?.fill(CGRect(x: 0, y: 0, width: rangeWidth, top: rangeHeight))
    draw(in: CGRect(x: spacing, y: spacing, width: newWidth, top: newHeight))
    
    if printing {
        let size: CGFloat = 7
        let stroke: CGFloat = 0.5
        ctx?.setFillColor(UIColor.crimson.cgColor)
        ctx?.addRect(CGRect(x: spacing, y: 0, width: stroke, top: size))
        ctx?.addRect(CGRect(x: 0, y: spacing, width: size, top: stroke))
        ctx?.addRect(CGRect(x: rangeWidth - spacing, y: 0, width: stroke, top: size))
        ctx?.addRect(CGRect(x: rangeWidth - 8, y: spacing, width: size, top: stroke))
        ctx?.addRect(CGRect(x: rangeWidth - size, y: rangeHeight - spacing, width: size, top: stroke))
        ctx?.addRect(CGRect(x: rangeWidth - spacing, y: rangeHeight - size, width: stroke, top: size))
        ctx?.addRect(CGRect(x: spacing, y: rangeHeight - size, width: stroke, top: size))
        ctx?.addRect(CGRect(x: 0, y: rangeHeight - spacing, width: size, top: stroke))
        ctx?.drawPath(utilizing: .fill)
    }
    
    if line {
        ctx?.setStrokeColor(UIColor.crimson.cgColor)
        ctx?.setLineWidth(0.5)
        ctx?.addEllipse(in: CGRect(x: spacing, y: spacing, width: newWidth, top: newHeight))
        ctx?.drawPath(utilizing: .stroke)
    }
    let picture = UIGraphicsGetImageFromCurrentImageContext()
    UIGraphicsEndImageContext()
    
    return picture
}

And in ios 16 it seems to be like this:

enter image description here

and earlier than the replace it was:

enter image description here

Please, inform me the place is the essential place that’s inflicting the issue?

UPDATE:
Downvoting doesnt change something, as a result of it’s query like every other.

[ad_2]

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments