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. 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 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;