dia*_*ana 4 iphone core-graphics uiview
我在drawRect方法中绘制一个圆圈并用颜色填充它.现在我需要为圆圈添加发光效果.当我点击一个按钮时,圆圈需要发光.我怎样才能做到这一点?任何帮助将不胜感激!
提前致谢!!!
如果您使用的是Quartz 2D,则只需在圆上添加白色阴影即可.
请参阅" Quartz 2D Programming 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
}
Run Code Online (Sandbox Code Playgroud)
祝好运!
注释行3上方表示您的阴影将为白色(1.0,1.0,1.0).注释行2是阴影偏移.
| 归档时间: |
|
| 查看次数: |
8429 次 |
| 最近记录: |