Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在iOS/swift中,在UITextView的边框周围放置阴影,使其具有3d效果_Ios_Swift_Xcode_Uitextview_Shadow - Fatal编程技术网

在iOS/swift中,在UITextView的边框周围放置阴影,使其具有3d效果

在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

有没有办法在UITextView的边界周围放置阴影,使其具有3D效果?textView具有圆角

我不想给文本视图的内容(即文本)添加阴影。仅在文本视图边框附近

我需要在文本视图中剪切圆角的边界

到目前为止,我一直在尝试:

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)
这导致:


原因:
剪辑到边界=真
阴影
在同一视图上不能同时工作。所以要解决这个问题,你必须遵循以下步骤

  • 在UIView中添加您的
    TextView
    (显示
    viewTextBG
  • TextView
    约束:上下、前导、尾随=0 wrt<代码>查看文本bg
  • textview
    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