在iOS/swift中,在UITextView的边框周围放置阴影,使其具有3d效果
有没有办法在UITextView的边界周围放置阴影,使其具有3D效果?textView具有圆角 我不想给文本视图的内容(即文本)添加阴影。仅在文本视图边框附近 我需要在文本视图中剪切圆角的边界 到目前为止,我一直在尝试:在iOS/swift中,在UITextView的边框周围放置阴影,使其具有3d效果,ios,swift,xcode,uitextview,shadow,Ios,Swift,Xcode,Uitextview,Shadow,有没有办法在UITextView的边界周围放置阴影,使其具有3D效果?textView具有圆角 我不想给文本视图的内容(即文本)添加阴影。仅在文本视图边框附近 我需要在文本视图中剪切圆角的边界 到目前为止,我一直在尝试: let shadowLayer = CAShapeLayer() shadowLayer.path = UIBezierPath(roundedRect: textView.bounds, cornerRadius: 15).cgPath shadowLayer.fillCol
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)
这导致:
原因:
剪辑到边界=真
和阴影
在同一视图上不能同时工作。所以要解决这个问题,你必须遵循以下步骤
TextView
(显示viewTextBG
)TextView
约束:上下、前导、尾随=0 wrt<代码>查看文本bgtextview
和viewTextBG
textview.cornerRadius = 10
viewTextBG.cornerRadius = 10
textview.clipsToBounds = True
viewTextBG.clipsToBounds = false
textview
和viewTextBG
textview.cornerRadius = 10
viewTextBG.cornerRadius = 10
textview.clipsToBounds = True
viewTextBG.clipsToBounds = false
viewTextBG
设置阴影现在一切都正常了,仅此而已。添加您尝试过的代码。编辑以反映我尝试过的代码是否正常?我的意思是阴影没有出现?阴影出现了,但覆盖了整个文本视图注释填充颜色和
textview.backgroundcolor=white
。并用fillColor=white