ios – 我怎么能概述文字字体?

前端之家收集整理的这篇文章主要介绍了ios – 我怎么能概述文字字体?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我想在其边框(轮廓)中显示另一种颜色的文本.
我正在尝试使用MapOverlayView显示文本
[text drawAtPoint:CGPointMake(0,30) withFont:[UIFont fontWithName:@"Helvetica-Bold" size:(3 * MKRoadWidthAtZoomScale(zoomScale))]

它工作正常,除了我需要文本显示轮廓.@H_403_6@

解决方法

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

使用kCGTextFillStroke似乎合乎逻辑,但这可能会使笔划压倒填充.如果你抚摸,然后填充,如下面的块中,你会得到可读文本背后的可见轮廓.@H_403_6@

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];
原文链接:https://www.f2er.com/iOS/327767.html

猜你在找的iOS相关文章