UIImageView* baseView = [[UIImageView alloc] init];
baseView.backgroundColor = [UIColor whiteColor];
//设置卡片阴影
baseView.layer.shadowColor = RGBACOLOR(42, 47, 59, 0.3).CGColor;
baseView.layer.shadowOffset = CGSizeMake(0, 2);
baseView.layer.shadowOpacity = 0.5;
baseView.layer.shadowRadius = 8;
baseView.layer.cornerRadius = 5;
//[baseView setImage:[UIImage imageNamed:@"home_cark_bg"]];
[self addSubview:baseView];
// // UIView+LXShadowPath.h // LXViewShadowPath // // Created by chenergou on 2017/11/23. // Copyright © 2017年 漫漫. All rights reserved. // #import <UIKit/UIKit.h> typedef enum :NSInteger{ LXShadowPathLeft, LXShadowPathRight, LXShadowPathTop, LXShadowPathBottom, LXShadowPathNoTop, LXShadowPathAllSide } LXShadowPathSide; @interface UIView (LXShadowPath) /* * shadowColor 阴影颜色 * * shadowOpacity 阴影透明度,默认0 * * shadowRadius 阴影半径,默认3 * * shadowPathSide 设置哪一侧的阴影, * shadowPathWidth 阴影的宽度, */ -(void)LX_SetShadowPathWith:(UIColor *)shadowColor shadowOpacity:(CGFloat)shadowOpacity shadowRadius:(CGFloat)shadowRadius shadowSide:(LXShadowPathSide)shadowPathSide shadowPathWidth:(CGFloat)shadowPathWidth; @end
// // UIView+LXShadowPath.m // LXViewShadowPath // // Created by chenergou on 2017/11/23. // Copyright © 2017年 漫漫. All rights reserved. // #import "UIView+LXShadowPath.h" @implementation UIView (LXShadowPath) /* * shadowColor 阴影颜色 * * shadowOpacity 阴影透明度,默认0 * * shadowRadius 阴影半径,默认3 * * shadowPathSide 设置哪一侧的阴影, * shadowPathWidth 阴影的宽度, */ -(void)LX_SetShadowPathWith:(UIColor *)shadowColor shadowOpacity:(CGFloat)shadowOpacity shadowRadius:(CGFloat)shadowRadius shadowSide:(LXShadowPathSide)shadowPathSide shadowPathWidth:(CGFloat)shadowPathWidth{ self.layer.masksToBounds = NO; self.layer.shadowColor = shadowColor.CGColor; self.layer.shadowOpacity = shadowOpacity; self.layer.shadowRadius = shadowRadius; self.layer.shadowOffset = CGSizeZero; CGRect shadowRect; CGFloat originX = 0; CGFloat originY = 0; CGFloat originW = self.bounds.size.width; CGFloat originH = self.bounds.size.height; switch (shadowPathSide) { case LXShadowPathTop: shadowRect = CGRectMake(originX, originY - shadowPathWidth/2, originW, shadowPathWidth); break; case LXShadowPathBottom: shadowRect = CGRectMake(originX, originH -shadowPathWidth/2, originW, shadowPathWidth); break; case LXShadowPathLeft: shadowRect = CGRectMake(originX - shadowPathWidth/2, originY, shadowPathWidth, originH); break; case LXShadowPathRight: shadowRect = CGRectMake(originW - shadowPathWidth/2, originY, shadowPathWidth, originH); break; case LXShadowPathNoTop: shadowRect = CGRectMake(originX -shadowPathWidth/2, originY +1, originW +shadowPathWidth,originH + shadowPathWidth/2 ); break; case LXShadowPathAllSide: shadowRect = CGRectMake(originX - shadowPathWidth/2, originY - shadowPathWidth/2, originW + shadowPathWidth, originH + shadowPathWidth); break; } UIBezierPath *path =[UIBezierPath bezierPathWithRect:shadowRect]; self.layer.shadowPath = path.CGPath; } @end