有没有办法在UITextView的边框周围放一个阴影给它一个3D效果? textView具有圆角 .
我不想为textView(即文本)的内容删除阴影 . 仅在textView边框周围 .
我需要在textView上使用clipToBounds作为圆角 .
到目前为止,这是我尝试过的:
let shadowLayer = CAShapeLayer()
shadowLayer.path = UIBezierPath(roundedRect: textView.bounds, cornerRadius: 15).cgPath
shadowLayer.fillColor = UIColor.clear.cgColor
shadowLayer.shadowColor = UIColor.black.cgColor
shadowLayer.shadowPath = shadowLayer.path
shadowLayer.shadowOffset = CGSize(width: 2, height: 2)
shadowLayer.shadowOpacity = 1
shadowLayer.shadowRadius = 2
textView.layer.addSublayer(shadowLayer)
这导致:
1 回答
Reason :
Clips to bounds = true
和shadow
在同一视图上,doest不能同时工作 . 所以要理清这一点,你必须遵循 .在UIView中添加
TextView
(说viewTextBG
) .TextView
约束:顶部底部,前导,尾部= 0 wrt .viewTextBG
.将圆角半径设为
textview
和viewTextBG
textview
和viewTextBG
viewTextBG
阴影 .现在一切正常,就是这样 .