我在drawRect方法中画了一个圆并用颜色填充它。现在我需要为圆圈添加发光效果。当我点击按钮时,圆圈需要发光。我怎样才能做到这一点?任何帮助将不胜感激!
提前致谢!!!
最佳答案
如果您使用 Quartz 2D,则只需向圆圈添加白色阴影即可。
请参阅Quartz 2D Programming Guide for Shadows
Apple 用于设置阴影的示例代码取自上面的链接:
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 是阴影偏移。
关于iphone - 为圆圈添加发光效果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1464283/