[英]drop shadow around border of UITextView to give it 3d effect in iOS/swift
有没有办法在 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)
这导致:
原因: Clips to bounds = true
和同一视图上的shadow
不能同时工作。 所以要解决这个问题,你必须遵循。
TextView
(说viewTextBG
)。TextView
约束:顶部底部,前导,尾随 = 0 wrt。 viewTextBG
。 为textview
和viewTextBG
赋予角半径
textview.cornerRadius = 10 viewTextBG.cornerRadius = 10
将 clipsToBounds 赋予textview
和viewTextBG
textview.clipsToBounds = True viewTextBG.clipsToBounds = false
现在给viewTextBG
提供阴影。
现在一切正常,仅此而已。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.