iOS UIView添加阴影

释放双眼,带上耳机,听听看~!
- (void)viewDidLoad {
    [super viewDidLoad];
    [self addShadowToView:_floatView withColor:[UIColor blackColor]];
}
 
/// 添加四边阴影效果
- (void)addShadowToView:(UIView *)theView withColor:(UIColor *)theColor {
    // 阴影颜色
    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.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文章

iOS UIView的圆角加阴影效果的实现

2019-11-21 10:20:42

iOS文章

IOS UIView周边加阴影,并且同时圆角

2019-11-21 14:14:51

个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
有新消息 消息中心
搜索