From 7df0be2bcf37b1e4aabe44949c3a04aa09ca1227 Mon Sep 17 00:00:00 2001 From: "actionsljx@foxmail.com" <actionsljx@foxmail.com> Date: Tue, 16 Jul 2024 14:23:16 +0800 Subject: [PATCH] =?UTF-8?q?FIX=20=20iOS=2017.0=20YYText=20UIGraphicsBeginI?= =?UTF-8?q?mageContextWithOptions=20=E5=B4=A9=E6=BA=83=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- YYText/Utility/YYTextAsyncLayer.m | 49 +++++++++++++++++-------------- 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/YYText/Utility/YYTextAsyncLayer.m b/YYText/Utility/YYTextAsyncLayer.m index 9f09700a..23348b28 100644 --- a/YYText/Utility/YYTextAsyncLayer.m +++ b/YYText/Utility/YYTextAsyncLayer.m @@ -200,28 +200,33 @@ - (void)_displayAsync:(BOOL)async { } else { [_sentinel increase]; if (task.willDisplay) task.willDisplay(self); - UIGraphicsBeginImageContextWithOptions(self.bounds.size, self.opaque, self.contentsScale); - CGContextRef context = UIGraphicsGetCurrentContext(); - if (self.opaque && context) { - CGSize size = self.bounds.size; - size.width *= self.contentsScale; - size.height *= self.contentsScale; - CGContextSaveGState(context); { - if (!self.backgroundColor || CGColorGetAlpha(self.backgroundColor) < 1) { - CGContextSetFillColorWithColor(context, [UIColor whiteColor].CGColor); - CGContextAddRect(context, CGRectMake(0, 0, size.width, size.height)); - CGContextFillPath(context); - } - if (self.backgroundColor) { - CGContextSetFillColorWithColor(context, self.backgroundColor); - CGContextAddRect(context, CGRectMake(0, 0, size.width, size.height)); - CGContextFillPath(context); - } - } CGContextRestoreGState(context); - } - task.display(context, self.bounds.size, ^{return NO;}); - UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); - UIGraphicsEndImageContext(); + UIGraphicsImageRendererFormat *format = [[UIGraphicsImageRendererFormat alloc] init]; + format.opaque = self.opaque; + format.scale = self.contentsScale; + + UIGraphicsImageRenderer *renderer = [[UIGraphicsImageRenderer alloc] initWithSize:self.bounds.size format:format]; + UIImage *image = [renderer imageWithActions:^(UIGraphicsImageRendererContext * _Nonnull rendererContext) { + CGContextRef context = rendererContext.CGContext; + if (self.opaque) { + CGSize size = self.bounds.size; + size.width *= self.contentsScale; + size.height *= self.contentsScale; + CGContextSaveGState(context); { + if (!self.backgroundColor || CGColorGetAlpha(self.backgroundColor) < 1) { + CGContextSetFillColorWithColor(context, [UIColor whiteColor].CGColor); + CGContextAddRect(context, CGRectMake(0, 0, size.width, size.height)); + CGContextFillPath(context); + } + if (self.backgroundColor) { + CGContextSetFillColorWithColor(context, self.backgroundColor); + CGContextAddRect(context, CGRectMake(0, 0, size.width, size.height)); + CGContextFillPath(context); + } + } CGContextRestoreGState(context); + } + task.display(context, self.bounds.size, ^{return NO;}); + }]; + self.contents = (__bridge id)(image.CGImage); if (task.didDisplay) task.didDisplay(self, YES); }