Diziet
Diziet

Reputation: 2417

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

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

Upvotes: 4

Views: 2047

Answers (3)

Roi Tal
Roi Tal

Reputation: 1000

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

Upvotes: 1

Guillaume Laurent
Guillaume Laurent

Reputation: 1744

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.

Upvotes: 1

filipe
filipe

Reputation: 3380

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

Upvotes: 11

Related Questions