我怎么能概述文字字体? [英] How could I outline Text font?

查看:82
本文介绍了我怎么能概述文字字体?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I would like to display text with another color in it's border (outline). i'm trying to display a text in MapOverlayView using

[text drawAtPoint:CGPointMake(0,30) withFont:[UIFont fontWithName:@"Helvetica-Bold" size:(3 * MKRoadWidthAtZoomScale(zoomScale))] 

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

it works fine except I need text to be displayed outlines.

推荐答案

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

Yes, you can display outlined text with the aid of CGContextSetDrawingMode(CGContextRef, CGTextDrawingMode), although you'll probably need to adjust some numbers and colors to make it look good.

使用kCGTextFillStroke似乎合乎逻辑,但这会使笔划压倒填充。如果你描边,然后填充,如下面的方块,你会得到可读文本背后的可见轮廓。

It make seem logical to use kCGTextFillStroke, but that can make the stroke overwhelm the fill. If you stroke, then fill, as in the block below, you get a visible outline behind readable text.

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];

这篇关于我怎么能概述文字字体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆