【发布时间】:2017-10-21 06:49:53
【问题描述】:
有没有办法在 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)
这会导致:
【问题讨论】:
-
添加您尝试过的代码。
-
编辑以反映我的尝试
-
所以代码不起作用?我的意思是影子没有出现?
-
阴影出现但覆盖整个文本视图
-
评论 fillColor 和
textview.backGroudColor = white。并检查fillColor= white
标签: ios swift xcode uitextview shadow