UIView設定陰影效果
阿新 • • 發佈:2019-01-07
UIView的陰影效果主要是通過UIView的layer的相關屬性來設定
陰影的顏色
shadowView.layer.shadowColor = [UIColor blackColor].CGColor;
陰影的透明度
shadowView.layer.shadowOpacity = 0.8f;
陰影的圓角
shadowView.layer.shadowRadius = 4.0f;
陰影的偏移量
shadowView.layer.shadowOffset = CGSizeMake(4,4);
shadowView.layer.shadowOffset = CGSizeMake(0,0);
其實從偏移量上可以看出來,即使偏移量為(0,0)時,圍繞view的四周依然能看到一定的陰影效果.
也可以通過設定路徑來設定陰影效果:
陰影路徑
UIBezierPath *path = [UIBezierPath bezierPath
];
[path moveToPoint:CGPointMake(-5, -5)];
//新增直線
[path addLineToPoint:CGPointMake(paintingWidth /2, -15)];
[path addLineToPoint:CGPointMake(paintingWidth +5, -5)];
[path addLineToPoint:CGPointMake(paintingWidth +15, paintingHeight /2)];
[path addLineToPoint:CGPointMake(paintingWidth +5, paintingHeight +5)];
[path addLineToPoint:CGPointMake(paintingWidth /2, paintingHeight +15)];
[path addLineToPoint:CGPointMake(-5, paintingHeight +5)];
[path addLineToPoint:CGPointMake(-15, paintingHeight /2)];
[path addLineToPoint:CGPointMake(-5, -5)];
//設定陰影路徑
imgView.layer.shadowPath = path.CGPath;