基于石英的投影在 UITextView 上对我不起作用
我已经能够向视图中的许多 UI 对象添加阴影,包括在 UIImageView 中很好地为一些自定义绘图添加阴影。然而,相同的代码在应用于 UITextView 时不会产生任何结果:
[desc.layer setShadowColor:[[UIColor blackColor] CGColor]];
[desc.layer setShadowRadius:2.0f];
[desc.layer setShadowOffset:CGSizeMake(1, 1)];
[desc.layer setShadowOpacity:0.8f];
这是我缺少的东西吗?我希望使用石英来添加边框和阴影。边界代码在注释时确实有效:
//Border.
/*
[desc.layer setBackgroundColor:[[KookaSettings sharedInstance].cellBackgroundColorD CGColor]];
[desc.layer setBorderColor: [[UIColor blackColor] CGColor]];
[desc.layer setBorderWidth:1.0f];
[desc.layer setCornerRadius:8.0f];
*/
I have been able to add shadows to many UI objects in my view, including rather nicely drop shadowing some custom drawing in a UIImageView. However the same code produces nothing when applied to a UITextView:
[desc.layer setShadowColor:[[UIColor blackColor] CGColor]];
[desc.layer setShadowRadius:2.0f];
[desc.layer setShadowOffset:CGSizeMake(1, 1)];
[desc.layer setShadowOpacity:0.8f];
Is this something I'm missing? I was hoping to use quartz to add a border and a drop shadow. The border code does work when commented in:
//Border.
/*
[desc.layer setBackgroundColor:[[KookaSettings sharedInstance].cellBackgroundColorD CGColor]];
[desc.layer setBorderColor: [[UIColor blackColor] CGColor]];
[desc.layer setBorderWidth:1.0f];
[desc.layer setCornerRadius:8.0f];
*/
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我知道如果视图设置了clipsToBounds,则投影不起作用。也许
UITextView
默认设置了这个?I know that the drop shadow doesn't work if the view has
clipsToBounds
set. PerhapsUITextView
has that set by default?对于阴影,您需要将 ClipsToBounds 设置为 NO,但缺点是,如果您的文本长于视图的可见区域并且需要滚动它,那么它将不再被剪切到视图的可见边界。我正在寻找一种干净的方法来解决这个问题。
You need to set clipsToBounds to NO for the shadow, but the downside is that if your text is longer than the visible area of the view and you need to scroll it, then it will no longer be clipped to the view's visible boundaries. I'm looking for a clean way around this.
Guillaume 关于 ClipsToBounds 设置的说法是正确的。
这有点乱,但你总是可以在 UITextView 后面添加一个清晰的视图并在其上放置阴影......
Guillaume is right about the clipsToBounds setting.
It's a little messy, but you can always add a clear view behind the UITextView and drop a shadow on it...