添加阴影的UITextView使文字扩大了UITextViewFrame
问题描述:
添加阴影的UITextView使文字扩大了UITextViewFrame
的我有一个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
它什么也不做,就像它塞汀假什么都不做。 因此,如果任何人有任何想法会有什么工作,帮助我,因为我卡住了。
答
不幸的是,如果您使用textview.clipsToBounds = true
比您的阴影将不可见。
我建议你设置textview.clipsToBounds = true
并插入另一UIView
具有相同的帧textview
和借鉴是UIView
阴影和圆角半径的textview
下方。
与UITextView
文本不会溢出它的边界,你将有阴影和圆角半径可见......
至于我看网上这可能是对于这种情况最好的解决方案。 – Stephanie