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

我想在其边框(轮廓)中显示另一种颜色的文本.
我正在尝试使用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];

相关文章

UITabBarController 是 iOS 中用于管理和显示选项卡界面的一...
UITableView的重用机制避免了频繁创建和销毁单元格的开销,使...
Objective-C中,类的实例变量(instance variables)和属性(...
从内存管理的角度来看,block可以作为方法的传入参数是因为b...
WKWebView 是 iOS 开发中用于显示网页内容的组件,它是在 iO...
OC中常用的多线程编程技术: 1. NSThread NSThread是Objecti...