我想创建一个带阴影的半圆UIView。保留蒙面UIView的阴影
我所做的是:
- 创建的UIView。
- 设置它的backgroundColor白
- 设置CornerRadius于是成了一个圆圈
使用view.layer.shadow性能
circleView.backgroundColor = UIColor.whiteColor(); circleView.layer.cornerRadius = baseRoundView.bounds.height/2 ; circleView.layer.shadowColor = UIColor.blackColor().CGColor; circleView.layer.shadowOffset = CGSize(width: 0, height: -3); circleView.layer.shadowOpacity = 0.1; circleView.layer.shadowRadius = 1;
添加阴影给它,但这些措施只得到了我一个完整的圆有阴影的UIVIEW。
所以我试图掩饰下半部
var maskRect: CGRect = CGRect(x: 0, y: 0), width: self.circleView.bounds.width, height: self.circleView.bounds.height/2);
var path = CGPathCreateWithRect(maskRect, nil);
maskLayer.path = path;
circleView.layer.mask = maskLayer;
这些措施运作良好,但我失去了顶部阴影
我期待什么有
任何想法?
阴影的偏移量在y上是-3。所以如果我没有记错的话,它会扩展真正的大小('clipsToBounds'为'false')。所以你也必须在面具上做-3(也可能在高度上+3)。 – Larme
谢谢Larme,那正是我需要的!用您的答案更新了问题 – JayVDiyk