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;
                }
            }];

github地址

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

  • 10
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值