gpt4 book ai didi

ios - 框架偏移时,NSAttributedString drawInRect消失

转载 作者:行者123 更新时间:2023-12-01 18:18:34 25 4
gpt4 key购买 nike

我有一个很奇怪的问题。当我偏移我用来画NSAttributedString的帧/矩形时

我的文字消失了。有什么想法吗?
这是具有40 px的简单偏移量的图像。

r.size = [self.text boundingRectWithSize:r.size
options:NSStringDrawingUsesLineFragmentOrigin
context:nil].size;
r.origin.y +=40;
[[UIColor orangeColor] setFill];
CGContextFillRect(ctx, r);
[self.text drawInRect:r];

结果:

这是 ,没有偏移量。

如何在给定的偏移量处绘制AttributedText?

最佳答案

我不知道为什么这个问题尚未解决。这是NSAttributedString API的一个严重问题,我希望Apple尽快在文档中或通过对实现进行修补来予以确认。

目前,您可以通过在绘制字符串之前转换图形上下文来解决此问题。

CGContextRef context = whatever;
CGContextSaveGState(context);
CGContextTranslateCTM(context, x, y);
// draw here
CGContextRestoreGState(context);

关于ios - 框架偏移时,NSAttributedString drawInRect消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19232850/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com