[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設置單邊陰影
最后編輯于 :
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
【社區(qū)內容提示】社區(qū)部分內容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發(fā)布,文章內容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。
【社區(qū)內容提示】社區(qū)部分內容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發(fā)布,文章內容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。
相關閱讀更多精彩內容
- 項目中有遇到一種情況 為有設置圓角的view或者button設置陰影,用常規(guī)寫法發(fā)現(xiàn)陰影添加無效,曾試過在需要添...
- box-shadow設置陰影效果 box-shadow: h-shadow,v-shadow,blur,sprea...
- 平時開發(fā)時總會有一些特殊的UI效果會比較煩人,比如單個邊的圓角,單個邊的陰影等等,下面我們使用一種很easy的方式...
- CSS3 box-shadow 效果大全[https://www.html.cn/archives/9360/]