有没有简单的方法或库让文字发光? [英] Is there an easy way or library available to let text glow?

查看:100
本文介绍了有没有简单的方法或库让文字发光?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想制作一个发光的文字,看起来好像是闪亮或发光。实际上,这将在背景中有些模糊。但我在iPhone SDK中没有发现任何内容。

I'd like to make a glowing text that looks like if it was shining or emmitting light. Actually this would be done with some blurryness in the background. But I've found nothing in the iPhone SDK that would do it.

推荐答案

你可以使用纯石英绘图来做到这一点。在-drawRect中:对于UIView或-renderInContext:对于CALayer,以下代码将绘制文本并在其周围应用光晕:

You can do this using pure Quartz drawing. Within -drawRect: for a UIView or -renderInContext: for a CALayer, the following code will draw text and apply a glow around it:

CGContextSetShadowWithColor( context, CGSizeMake( 0.0, 0.0 ), 20.0f, glowColor );   

[text drawAtPoint:CGPointMake(0.5f, 0.5f) withFont:[UIFont fontWithName:@"Helvetica" size:16.0f]];

其中text是NSString,而glowColor是要应用的glow的CGColorRef。此示例将绘制一个从16点Helvetica文本延伸出20像素的光晕,并以文本为中心。

where text is an NSString, and glowColor is a CGColorRef for the glow you want to apply. This example will draw a glow that extends out 20 pixels from the 16-point Helvetica text, and is centered on the text.

您可以通过提供不同的位移(第一个函数中的第二个参数)以及使用黑色CGColor作为阴影,轻松将其转换为阴影。

You can easily convert this into a shadow by providing a different displacement (second argument in the first function) and by using a black CGColor for the shadow.

这篇关于有没有简单的方法或库让文字发光?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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