sketch中的shadow这些属性,如果直接对应iOS的layer上的属性有很多是找不到的.譬如 blur,spread
在stackoverflow上有相关的内容 https://stackoverflow.com/questions/34269399/how-to-control-shadow-spread-and-blur
虽然没有直接对应的layer属性,但是可以通过相关计算得到.可以为CALayer写个分类
/**
apply to sketch shadow values
@param color shadow color
@param alpha shadow opacity
@param x x
@param y y
@param blur blur
@param spread spread
*/
-(void)applySketchShadowWithColor:(UIColor *)color
alpha:(float)alpha
x:(CGFloat)x
y:(CGFloat)y
blur:(CGFloat)blur
spread:(CGFloat)spread
{
self.shadowColor = color.CGColor;
self.shadowOpacity = alpha;
self.shadowOffset = (CGSize){x,y};
self.shadowRadius = blur / 2.0;
if (spread == 0) {
self.shadowPath = nil;
} else {
CGFloat dx = -spread;
CGRect rect = CGRectInset(self.bounds, dx, dx);
self.shadowPath = [UIBezierPath bezierPathWithRect:rect].CGPath;
}
}