gpt4 book ai didi

ios - coretext 从文本字段的底部到顶部显示文本

转载 作者:行者123 更新时间:2023-11-28 22:36:57 24 4
gpt4 key购买 nike

我正在绘制一个文本字段,并且已将一个文本字段添加到 UIView 中。文本位于路径内。它绘制正确,但内容从底部开始到顶部结束。有办法解决这个问题吗?

这是我的代码:

// Draw text into a circle using Core Text and Quartz
- (void) drawRect:(CGRect)rect
{
[super drawRect: rect];

CGContextRef context = UIGraphicsGetCurrentContext();
self.layer.rasterizationScale = [[UIScreen mainScreen] scale];

// Flip the context
CGContextTranslateCTM(context, 0, 3);
CGContextSetTextMatrix(context, CGAffineTransformIdentity);

CGContextSetTextMatrix(context, CGAffineTransformMakeScale(1.0f, -1.0f));


// Stroke that path
CGContextAddPath(context, backPath);
CGContextSetLineWidth(context, 1.0f);
//[[UIColor blackColor] setStroke];
CGContextStrokePath(context);

// Fill that path
CGContextAddPath(context, backPath);
[[UIColor whiteColor] setFill];
CGContextFillPath(context);

CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString((CFAttributedStringRef)string);
CTFrameRef theFrame = CTFramesetterCreateFrame(framesetter, CFRangeMake(0, string.length),backPath, NULL);
CTFrameDraw(theFrame, context);

CFRelease(framesetter);
CFRelease(theFrame);
CFRelease(backPath);

}

我的路径是这样的:

 - (id) initWithAttributedString: (NSAttributedString *) aString path:   (vector<ofPoint>)paths
{
backPath = CGPathCreateMutable();

CGPathMoveToPoint(backPath, NULL, paths[0].x, paths[0].y); // Bottom left

for(int x=1; x< paths.size(); x++){
CGPathAddLineToPoint(backPath, NULL, paths[x].x,paths[x].y); // Bottom right
}
CGPathCloseSubpath(backPath);

if (!(self = [super initWithFrame:CGRectZero])) return self;

self.backgroundColor = [UIColor clearColor];
string = aString;
return self;
}

img

并制作文本字段:

  path.push_back(ofPoint(ofGetWidth()/4,ofGetHeight()/4));
// point to user
// path.push_back(ofPoint((position.x-(ofGetWidth()/4))/2,ofGetHeight()/4));
// point to right top
path.push_back(ofPoint(ofGetWidth()/4,ofGetHeight()/4));
// point to end x, pos y user
path.push_back(ofPoint((ofGetWidth()/4),(position.y-(ofGetHeight()/4))/2));

path.push_back(ofPoint((position.x-(ofGetWidth()/4))/2-100,(position.y-(ofGetHeight()/4))/2-100));

path.push_back(ofPoint((position.x-(ofGetWidth()/4))/2,(position.y-(ofGetHeight()/4))/2));

最佳答案

你正在翻转文本矩阵。相反,翻转整个 CTM:

CGContextScaleCTM(context, 1, -1);
CGContextTranslateCTM(context, 0, self.bounds.size.height);

关于ios - coretext 从文本字段的底部到顶部显示文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15666325/

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