Quartz based drop shadows don't work for me on UITextView

浪尽此生 提交于 2019-12-10 15:44:56

问题


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];
*/

回答1:


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




回答2:


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.




回答3:


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



来源:https://stackoverflow.com/questions/4401730/quartz-based-drop-shadows-dont-work-for-me-on-uitextview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!