美文网首页
iOS UIView 添加阴影

iOS UIView 添加阴影

作者: WS_0909 | 来源:发表于2018-11-02 17:05 被阅读0次
    
     
    #pragma mark - 添加阴影效果
    - (void)addShadowToView:(UIView *)theView withColor:(UIColor *)theColor {
    
        theView.layer.masksToBounds = NO;
        // 阴影颜色
        theView.layer.shadowColor = theColor.CGColor;
        // 阴影偏移,默认(0, -3)
        theView.layer.shadowOffset = CGSizeMake(0,0);
        // 阴影透明度,默认0
        theView.layer.shadowOpacity = 0.5;
        // 阴影半径,默认3
        theView.layer.shadowRadius = 5;
    }
    
    添加单边阴影效果
    - (void)addShadowToView:(UIView *)theView withColor:(UIColor *)theColor {
    
        theView.layer.masksToBounds = NO;
        theView.layer.shadowColor = theColor.CGColor;
        theView.layer.shadowOffset = CGSizeMake(0,0);
        theView.layer.shadowOpacity = 0.5;
        theView.layer.shadowRadius = 5;
        // 单边阴影 顶边
        float shadowPathWidth = theView.layer.shadowRadius;
        CGRect shadowRect = CGRectMake(0, 0-shadowPathWidth/2.0, theView.bounds.size.width, shadowPathWidth);
        UIBezierPath *path = [UIBezierPath bezierPathWithRect:shadowRect];
        theView.layer.shadowPath = path.CGPath;
    }
    
    

    相关文章

      网友评论

          本文标题:iOS UIView 添加阴影

          本文链接:https://www.haomeiwen.com/subject/abpcxqtx.html