给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];
}