【发布时间】:2017-10-19 13:54:38
【问题描述】:
我有一个 UITextView,我想给它添加阴影。我使用的代码是:
textview.layer.shadowColor = UIColor.lightGray.cgColor
textview.layer.shadowOffset = CGSize(width:0,height: 2.0)
textview.layer.shadowRadius = 2.0
textview.layer.shadowOpacity = 1.0
textview.layer.masksToBounds = false
textview.layer.cornerRadius = 5
此代码添加了阴影并使角变圆,但它也使 UITextView 内的文本超出了 textview 框架。 我尝试添加
textview.clipToBounds = true
这会将文本设置在内部,但会移除阴影。我也试过设置:
textview.layer.maskToBounds = true
textview.clipToBounds = false
但问题重演。 我在这里读到了我应该设置的地方
textview.layer.shouldRasterize = true
它什么都不做,就像将它设置为 false 什么都不做一样。 因此,如果有人知道什么会起作用,请帮助我,因为我被卡住了。
【问题讨论】:
标签: ios swift xcode uitextview shadow