gpt4 book ai didi

ios - 我怎样才能概述文本字体?

转载 作者:可可西里 更新时间:2023-11-01 03:47:54 28 4
gpt4 key购买 nike

我想在其边框(轮廓)中显示另一种颜色的文本。我正在尝试使用

在 MapOverlayView 中显示文本
[text drawAtPoint:CGPointMake(0,30) withFont:[UIFont fontWithName:@"Helvetica-Bold" size:(3 * MKRoadWidthAtZoomScale(zoomScale))] 

它工作正常,除了我需要显示轮廓的文本。

最佳答案

是的,您可以借助 CGContextSetDrawingMode(CGContextRef, CGTextDrawingMode) 显示带轮廓的文本,尽管您可能需要调整一些数字和颜色以使其看起来不错。

使用 kCGTextFillStroke 看起来合乎逻辑,但这会使笔划压倒填充。如果先描边,然后填充,如下图所示,您会在可读文本后面看到一个可见的轮廓。

CGContextRef context = UIGraphicsGetCurrentContext();

CGPoint point = CGPointMake(0,30);
CGFloat fontSize = (3 * MKRoadWidthAtZoomScale(zoomScale));
UIFont *font = [UIFont fontWithName:@"Helvetica-Bold" size:fontSize];

// Draw outlined text.
CGContextSetTextDrawingMode(context, kCGTextStroke);
// Make the thickness of the outline a function of the font size in use.
CGContextSetLineWidth(context, fontSize/18);
CGContextSetStrokeColorWithColor(context, [[UIColor redColor] CGColor]);
[text drawAtPoint:point withFont:font];

// Draw filled text. This will make sure it's clearly readable, while leaving some outline behind it.
CGContextSetTextDrawingMode(context, kCGTextFill);
CGContextSetFillColorWithColor(context, [[UIColor blueColor] CGColor]);
[text drawAtPoint:point withFont:font];

关于ios - 我怎样才能概述文本字体?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10036671/

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