当前位置:   article > 正文

YYText iOS17兼容问题

yytext ios17

使用YYText ,1.0.7在iOS17会遇到如下崩溃
在这里插入图片描述
主要原因是UIGraphicsBeginImageContext中的asert引发,而改接口早就标记为API_TO_BE_DEPRECATED,建议使用UIGraphicsImageRenderer替换。
由于YYText早已没有维护,于是fork了一个自己的git进行修正,主要修正逻辑在textAsynLayer

在这里插入图片描述
替换为

            UIGraphicsImageRenderer *renderer = [[UIGraphicsImageRenderer alloc] initWithSize:size];
            UIImage *image = [renderer imageWithActions:^(UIGraphicsImageRendererContext * _Nonnull context) {
                if (opaque) {
                    CGContextSaveGState(context.CGContext); {
                        if (!backgroundColor || CGColorGetAlpha(backgroundColor) < 1) {
                            CGContextSetFillColorWithColor(context.CGContext, [UIColor whiteColor].CGColor);
                            CGContextAddRect(context.CGContext, CGRectMake(0, 0, size.width * scale, size.height * scale));
                            CGContextFillPath(context.CGContext);
                        }
                        if (backgroundColor) {
                            CGContextSetFillColorWithColor(context.CGContext, backgroundColor);
                            CGContextAddRect(context.CGContext, CGRectMake(0, 0, size.width * scale, size.height * scale));
                            CGContextFillPath(context.CGContext);
                        }
                    } CGContextRestoreGState(context.CGContext);
                    CGColorRelease(backgroundColor);
                }
                task.display(context.CGContext, size, isCancelled);
                if (isCancelled()) {
                    dispatch_async(dispatch_get_main_queue(), ^{
                        if (task.didDisplay) task.didDisplay(self, NO);
                    });
                    return;
                }
            }];

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26

github地址

具体可参见git@github.com:iamanthonyzhu/YYTextAsynLayer.git

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/繁依Fanyi0/article/detail/509925
推荐阅读
相关标签
  

闽ICP备14008679号