我给带有圆角的视图添加了阴影,它起作用了。但是当视图的frame
改变时,shadow
不会根据视图改变大小。
我尝试了以下方法:
-(void)addShadow:(UIView *)view withCornerRad : (int)radius{
view.clipsToBounds = YES;
CALayer *ViewLayer = view.layer;
[ViewLayer setMasksToBounds:NO ];
ViewLayer.shadowColor = [UIColor lightGrayColor].CGColor;
ViewLayer.shadowOpacity = 1.0 ;
ViewLayer.shadowRadius = 2.0 ;
ViewLayer.shadowOffset = CGSizeMake( 0 , 0 );
ViewLayer.cornerRadius = radius;
ViewLayer.shadowPath = [UIBezierPath bezierPathWithRect:view.bounds].CGPath;
}