let bgView = UIView(frame: .zero)
bgView.frame = CGRect(x: 0, y: 0, width: 375, height: 50)
self.addSubview(bgView)
bgView.layer.shadowOffset = CGSize(width: 0, height: 7)
bgView.layer.shadowRadius = 5.0;
bgView.layer.shadowColor = UIColor.black.cgColor
bgView.layer.shadowOpacity = 0.8;
如上,给一个Tableview上的UIView添加很简单阴影,但是却显示不出来
主要原因是UIView背景色默认是透明,要设置一个背景色才行
bgView.backgroundColor = .white
当然也可能设置了这个属性,为true阴影会被切掉
bgView.layer.masksToBounds = true
网友评论