控件阴影

扩展

920 发布: 2021/4/20 15:08 本文总阅读量
UIview扩展

四周阴影

-(void)rk_shadowWithColor: (UIColor *)color offset: (CGSize)offset opacity: (CGFloat)opacity radius: (CGFloat)radius{

    self.clipsToBounds = NO;
    self.layer.shadowColor = color.CGColor;
    self.layer.shadowOffset = offset;
    self.layer.shadowOpacity = opacity;
    self.layer.shadowRadius = radius;
    
    CGRect rec = CGRectMake(-offset.width, -offset.height, self.bounds.size.width+offset.width*2, self.bounds.size.height+offset.height*2);
    self.layer.shadowPath = [UIBezierPath bezierPathWithRect:rec].CGPath;
}