基于石英的投影在 UITextView 上对我不起作用

发布于 2024-10-07 11:48:07 字数 616 浏览 0 评论 0原文

我已经能够向视图中的许多 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

盗梦空间 2024-10-14 11:48:07

我知道如果视图设置了clipsToBounds,则投影不起作用。也许 UITextView 默认设置了这个?

I know that the drop shadow doesn't work if the view has clipsToBounds set. Perhaps UITextView has that set by default?

撩人痒 2024-10-14 11:48:07

对于阴影,您需要将 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.

爱人如己 2024-10-14 11:48:07

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...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文