【发布时间】:2015-06-05 12:21:37
【问题描述】:
我正在尝试创建一个带阴影的半圆形 UIView。
我所做的是:
- 创建一个 UIView。
- 将其背景颜色设置为白色
- 将 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;但是这些步骤只给了我一个带阴影的 FULL CIRCLE 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)。 -
谢谢拉姆,这正是我所需要的!用你的答案更新了问题
标签: ios swift uiview custom-controls calayer