UIView影子,cornerradius不工作

时间:2017-04-23 04:08:35

标签: ios swift uiview

@IBOutlet weak var selectorSemiView: UIView!
@IBOutlet weak var blurEffect: UIVisualEffectView!
@IBOutlet var outerAreaRecognizer: UITapGestureRecognizer!
override func viewDidLoad() {
    super.viewDidLoad()
    selectorSemiView.layer.cornerRadius = 15
    selectorSemiView.layer.shadowColor = UIColor.gray.cgColor
    selectorSemiView.layer.shadowOffset = CGSize.zero
    selectorSemiView.layer.shadowRadius = 7

}

selectorSemiView是一个容器视图

当我运行此应用程序时,没有阴影也没有圆角。

我的代码有什么问题?

2 个答案:

答案 0 :(得分:5)

您的代码没问题,但是您忘了设置不透明度,如果您需要更多信息,可以在SO中获得另一个答案,例如

 selectorSemiView.layer.cornerRadius = 15
    selectorSemiView.layer.shadowColor = UIColor.gray.cgColor
    selectorSemiView.layer.shadowOffset = CGSize.zero  
    selectorSemiView.layer.shadowOpacity = 1.0
    selectorSemiView.layer.shadowRadius = 7.0
    selectorSemiView.layer.masksToBounds =  false

<强>输出

enter image description here

答案 1 :(得分:1)

你需要添加

selectorSemiView.clipsToBounds = true