为圆圈添加发光效果 [英] Adding glowing effect to the circle

查看:182
本文介绍了为圆圈添加发光效果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在drawRect方法中绘制一个圆圈并用颜色填充它。现在我需要为圆圈添加发光效果。当我点击一个按钮时,圆圈需要发光。我怎样才能做到这一点?任何帮助将不胜感激!

I draw a circle in the drawRect method and fill it with a color. Now i need to add a glowing effect to the circle. When i click on a button, the circle needs to glow. How can i do this? Any help will be greatly appreciated!

提前致谢!!!

推荐答案

如果您使用的是Quartz 2D,则只需在圆圈上添加白色阴影。

If you are using Quartz 2D, you can simply add a white shadow to the circle.

请参阅 Quartz 2D阴影编程指南

Apple的示例代码,用于设置从上面的链接获取的阴影:

Apple's Sample code for setting up a shadow taken from the link above:

void MyDrawWithShadows (CGContextRef myContext, // 1
                         float wd, float ht);
{
    CGSize          myShadowOffset = CGSizeMake (-15,  20);// 2
    float           myColorValues[] = {1.0, 1.0, 1.0, .6};// 3 (White shadow colour)
    CGColorRef      myColor;// 4
    CGColorSpaceRef myColorSpace;// 5

    CGContextSaveGState(myContext);// 6

    CGContextSetShadow (myContext, myShadowOffset, 5); // 7

    // Your drawing code here!!!!!!!!!!!!!!!!   // 8

    CGContextSetRGBFillColor (myContext, 0, 1, 0, 1);
    CGContextFillRect (myContext, CGRectMake (wd/3 + 75, ht/2 , wd/4, ht/4));

    myColorSpace = CGColorSpaceCreateDeviceRGB ();// 9
    myColor = CGColorCreate (myColorSpace, myColorValues);// 10
    CGContextSetShadowWithColor (myContext, myShadowOffset, 5, myColor);// 11
    // Your drawing code here// 12
    CGContextSetRGBFillColor (myContext, 0, 0, 1, 1);
    CGContextFillRect (myContext, CGRectMake (wd/3-75,ht/2-100,wd/4,ht/4));

    CGColorRelease (myColor);// 13
    CGColorSpaceRelease (myColorSpace); // 14

    CGContextRestoreGState(myContext);// 15
}

祝你好运!

评论专栏3以上意味着你的影子将是白色的(1.0,1.0,1.0)。
注释行2是阴影偏移量。

Comment line 3 Above means your shadow will be white (1.0, 1.0, 1.0). Comment line 2 is the shadow offset.

这篇关于为圆圈添加发光效果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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