From 84b7897f22e86187499e2a84ff85e17f62721ea2 Mon Sep 17 00:00:00 2001 From: melontao Date: Sat, 26 Aug 2023 10:54:33 +0800 Subject: [PATCH 1/3] Update README.md --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 3a3b5d3..d2d9ffa 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ [![Carthage Compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)  [![SPM supported](https://img.shields.io/badge/SPM-supported-DE5C43.svg?style=flat)](https://swift.org/package-manager)  [![Platform](https://img.shields.io/cocoapods/p/MPITextKit.svg?style=flat)](http://cocoadocs.org/docsets/MPITextKit)  -[![Support](https://img.shields.io/badge/support-iOS%209%2B%20-blue.svg?style=flat)](https://www.apple.com/nl/ios/)  +[![Support](https://img.shields.io/badge/support-iOS%2010%2B%20-blue.svg?style=flat)](https://www.apple.com/nl/ios/)  Powerful text framework for iOS to display rich text based on TextKit, inspired by [Texture](https://github.com/texturegroup/texture) and [YYText](https://github.com/ibireme/YYText). @@ -27,14 +27,14 @@ Powerful text framework for iOS to display rich text based on TextKit, inspired - High performance asynchronous text layout and rendering - Text attachments with UIImage, UIView and CALayer - Exclusion paths -- Custom attribute +- Custom attributes - Custom truncation token - Debug text layout - Text selection ## Requirements -- iOS 9+ +- iOS 10+ ## Installation From 0adfff9d668218d85d9f5191d5cdf1e8f7176c6a Mon Sep 17 00:00:00 2001 From: melontao Date: Sat, 26 Aug 2023 10:55:18 +0800 Subject: [PATCH 2/3] Use UIGraphicsImageRenderer instead of UIGraphicsBeginImageContextWithOptions --- Sources/MPITextMagnifier.m | 103 ++++++++++++++++++------------------- 1 file changed, 51 insertions(+), 52 deletions(-) diff --git a/Sources/MPITextMagnifier.m b/Sources/MPITextMagnifier.m index e3e64d0..178f5b0 100644 --- a/Sources/MPITextMagnifier.m +++ b/Sources/MPITextMagnifier.m @@ -87,60 +87,59 @@ + (UIImage *)coverImage { CGRect rect = (CGRect) {.size = size, .origin = CGPointZero}; rect = CGRectInset(rect, kPadding, kPadding); - UIGraphicsBeginImageContextWithOptions(size, NO, 0); - CGContextRef context = UIGraphicsGetCurrentContext(); - - CGPathRef boxPath = CGPathCreateWithRect(CGRectMake(0, 0, size.width, size.height), NULL); - CGPathRef fillPath = CGPathCreateWithEllipseInRect(rect, NULL); - CGPathRef strokePath = CGPathCreateWithEllipseInRect(MPITextCGRectPixelHalf(rect), NULL); - - // inner shadow - CGContextSaveGState(context); { - CGFloat blurRadius = 25; - CGSize offset = CGSizeMake(0, 15); - CGColorRef shadowColor = [UIColor colorWithWhite:0 alpha:0.16].CGColor; - CGColorRef opaqueShadowColor = CGColorCreateCopyWithAlpha(shadowColor, 1.0); - CGContextAddPath(context, fillPath); - CGContextClip(context); - CGContextSetAlpha(context, CGColorGetAlpha(shadowColor)); - CGContextBeginTransparencyLayer(context, NULL); { - CGContextSetShadowWithColor(context, offset, blurRadius, opaqueShadowColor); - CGContextSetBlendMode(context, kCGBlendModeSourceOut); - CGContextSetFillColorWithColor(context, opaqueShadowColor); + UIGraphicsImageRendererFormat *format = [[UIGraphicsImageRendererFormat alloc] init]; + UIGraphicsImageRenderer *renderer = [[UIGraphicsImageRenderer alloc] initWithSize:size format:format]; + UIImage *image = [renderer imageWithActions:^(UIGraphicsImageRendererContext * _Nonnull rendererContext) { + CGContextRef context = rendererContext.CGContext; + CGPathRef boxPath = CGPathCreateWithRect(CGRectMake(0, 0, size.width, size.height), NULL); + CGPathRef fillPath = CGPathCreateWithEllipseInRect(rect, NULL); + CGPathRef strokePath = CGPathCreateWithEllipseInRect(MPITextCGRectPixelHalf(rect), NULL); + + // inner shadow + CGContextSaveGState(context); { + CGFloat blurRadius = 25; + CGSize offset = CGSizeMake(0, 15); + CGColorRef shadowColor = [UIColor colorWithWhite:0 alpha:0.16].CGColor; + CGColorRef opaqueShadowColor = CGColorCreateCopyWithAlpha(shadowColor, 1.0); CGContextAddPath(context, fillPath); - CGContextFillPath(context); - } CGContextEndTransparencyLayer(context); - CGColorRelease(opaqueShadowColor); - } CGContextRestoreGState(context); - - // outer shadow - CGContextSaveGState(context); { - CGContextAddPath(context, boxPath); - CGContextAddPath(context, fillPath); - CGContextEOClip(context); - CGColorRef shadowColor = [UIColor colorWithWhite:0 alpha:0.32].CGColor; - CGContextSetShadowWithColor(context, CGSizeMake(0, 1.5), 3, shadowColor); - CGContextBeginTransparencyLayer(context, NULL); { + CGContextClip(context); + CGContextSetAlpha(context, CGColorGetAlpha(shadowColor)); + CGContextBeginTransparencyLayer(context, NULL); { + CGContextSetShadowWithColor(context, offset, blurRadius, opaqueShadowColor); + CGContextSetBlendMode(context, kCGBlendModeSourceOut); + CGContextSetFillColorWithColor(context, opaqueShadowColor); + CGContextAddPath(context, fillPath); + CGContextFillPath(context); + } CGContextEndTransparencyLayer(context); + CGColorRelease(opaqueShadowColor); + } CGContextRestoreGState(context); + + // outer shadow + CGContextSaveGState(context); { + CGContextAddPath(context, boxPath); CGContextAddPath(context, fillPath); - [[UIColor colorWithWhite:0.7 alpha:1.000] setFill]; - CGContextFillPath(context); - } CGContextEndTransparencyLayer(context); - } CGContextRestoreGState(context); - - // stroke - CGContextSaveGState(context); { - CGContextAddPath(context, strokePath); - [[UIColor colorWithWhite:0.6 alpha:1] setStroke]; - CGContextSetLineWidth(context, MPITextCGFloatFromPixel(1)); - CGContextStrokePath(context); - } CGContextRestoreGState(context); - - CFRelease(boxPath); - CFRelease(fillPath); - CFRelease(strokePath); - - image = UIGraphicsGetImageFromCurrentImageContext(); - UIGraphicsEndImageContext(); + CGContextEOClip(context); + CGColorRef shadowColor = [UIColor colorWithWhite:0 alpha:0.32].CGColor; + CGContextSetShadowWithColor(context, CGSizeMake(0, 1.5), 3, shadowColor); + CGContextBeginTransparencyLayer(context, NULL); { + CGContextAddPath(context, fillPath); + [[UIColor colorWithWhite:0.7 alpha:1.000] setFill]; + CGContextFillPath(context); + } CGContextEndTransparencyLayer(context); + } CGContextRestoreGState(context); + + // stroke + CGContextSaveGState(context); { + CGContextAddPath(context, strokePath); + [[UIColor colorWithWhite:0.6 alpha:1] setStroke]; + CGContextSetLineWidth(context, MPITextCGFloatFromPixel(1)); + CGContextStrokePath(context); + } CGContextRestoreGState(context); + + CFRelease(boxPath); + CFRelease(fillPath); + CFRelease(strokePath); + }]; }); return image; From e82140367d60c55b66ceab9e923f5688ff02d203 Mon Sep 17 00:00:00 2001 From: melontao Date: Sat, 26 Aug 2023 10:55:37 +0800 Subject: [PATCH 3/3] Update MPITextKit.podspec --- MPITextKit.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MPITextKit.podspec b/MPITextKit.podspec index 1b8ae1c..4c7c955 100644 --- a/MPITextKit.podspec +++ b/MPITextKit.podspec @@ -8,7 +8,7 @@ Pod::Spec.new do |s| s.name = 'MPITextKit' - s.version = '0.2.1' + s.version = '0.2.2' s.summary = 'Powerful text framework for iOS to display text based on TextKit.' # This description is used to generate tags and improve search results.