您的位置:首页 > 产品设计 > UI/UE

iOS 给一个uiview设置shadow

2012-03-30 17:47 411 查看
给view设置shadow 主要是操作的caller上的,所以我们要先导入头文件
#import
<QuartzCore/QuartzCore.h>

然后,在函数

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event

{

    CALayer *layer =
self.layer;

    [layer setBorderColor:[[UIColor
yellowColor] CGColor]];//边框的颜色

    layer.shadowOffset =
CGSizeMake(0,
3);

    layer.shadowRadius =
5.0;

    layer.shadowColor = [UIColor
yellowColor].CGColor;//shadow的颜色

    layer.shadowOpacity =
0.8;

    [layer setBorderWidth:2.75];

}

touch结束后,设置回来

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
   

    CALayer *layer =
self.layer;
//这里的rgba可以自己设置
    [layer
setBorderColor:[[UIColor
colorWithRed:0.588
green:0.737
blue:0.976
alpha:1.0]
CGColor]];
    layer.shadowOffset =
CGSizeMake(0,
8);
    layer.shadowRadius =
5.0;
    layer.shadowColor = [UIColor
blackColor].CGColor;
    layer.shadowOpacity =
0.8;
    [layer
setBorderWidth:2.75];

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  uiview ios layer