[Tool view:bottomV shadowPathWithColor:rgba(0, 0, 0, 0.09) shadowOpacity:1 shadowRadius:2.5 shadowPathType:1 shadowPathWidth:2];
+ (void)view:(UIView *)view shadowPathWithColor:(UIColor *)shadowColor shadowOpacity:(CGFloat)shadowOpacity shadowRadius:(CGFloat)shadowRadius shadowPathType:(NSInteger)shadowPathType shadowPathWidth:(CGFloat)shadowPathWidth{
view.layer.masksToBounds = NO;//必须要等于NO否则会把阴影切割隐藏掉
view.layer.shadowColor = shadowColor.CGColor;// 阴影颜色
view.layer.shadowOpacity = shadowOpacity;// 阴影透明度,默认0
view.layer.shadowOffset = CGSizeZero;//shadowOffset阴影偏移,默认(0, -3),这个跟shadowRadius配合使用
view.layer.shadowRadius = shadowRadius;//阴影半径,默认3
CGRect shadowRect = CGRectZero;
CGFloat originX,originY,sizeWith,sizeHeight;
originX = 0;
originY = 0;
sizeWith = view.bounds.size.width;
sizeHeight = view.bounds.size.height;
if (shadowPathType == 1) {
//top
shadowRect = CGRectMake(originX, originY-shadowPathWidth/2, sizeWith, shadowPathWidth);
}else if (shadowPathType == 2){
//bottom
shadowRect = CGRectMake(originY, sizeHeight-shadowPathWidth/2, sizeWith, shadowPathWidth);
}else if (shadowPathType == 3){
//left
shadowRect = CGRectMake(originX-shadowPathWidth/2, originY, shadowPathWidth, sizeHeight);
}else if (shadowPathType == 4){
//right
shadowRect = CGRectMake(sizeWith-shadowPathWidth/2, originY, shadowPathWidth, sizeHeight);
}else if (shadowPathType == 5){
//普通
shadowRect = CGRectMake(originX-shadowPathWidth/2, 2, sizeWith+shadowPathWidth, sizeHeight+shadowPathWidth/2);
}else if (shadowPathType == 6){
//圆
shadowRect = CGRectMake(originX-shadowPathWidth/2, originY-shadowPathWidth/2, sizeWith+shadowPathWidth, sizeHeight+shadowPathWidth);
}
UIBezierPath *bezierPath = [UIBezierPath bezierPathWithRect:shadowRect];
view.layer.shadowPath = bezierPath.CGPath;//阴影路径
}
view设置单边阴影
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 项目中有遇到一种情况 为有设置圆角的view或者button设置阴影,用常规写法发现阴影添加无效,曾试过在需要添...
- box-shadow设置阴影效果 box-shadow: h-shadow,v-shadow,blur,sprea...
- 平时开发时总会有一些特殊的UI效果会比较烦人,比如单个边的圆角,单个边的阴影等等,下面我们使用一种很easy的方式...
- CSS3 box-shadow 效果大全[https://www.html.cn/archives/9360/]