[英]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.