Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create shadow using QuartzCore for UITextView [duplicate]

I have created a shadow using QuartzCore for my UITextView with this following code.

myTextView.layer.masksToBounds = NO;
myTextView.layer.shadowColor = [UIColor blackColor].CGColor;
myTextView.layer.shadowOpacity = 0.7f;
myTextView.layer.shadowOffset = CGSizeMake(2.0f, 2.0f);
myTextView.layer.shadowRadius = 8.0f;
myTextView.layer.shouldRasterize = YES;

It creates a shadow and looks good too. Here it is my output for the above code.

enter image description here

But When I try to add a text to the myTextView, my textView text goes out of the bounds and it looks outside of the myTextView like below.

enter image description here

It's happening only when I add shadow. The text inside the textView is not showing weird If I don't add shadow.What I am doing wrong?? How could I overcome this? Why it is happening?

UPDATE:

@borrrden said I found It is happening, because of setting the maskToBounds = NO; If we set YES then we cannot get shadow. Reason Here it is an answer

like image 495
Dinesh Raja Avatar asked Mar 06 '26 17:03

Dinesh Raja


1 Answers

There is no "right" solution, because of UIView behavior. When masksToBounds is NO, any sublayers that extend outside the layer's boundaries will be visible. And UITextField scroll text outside the UITextField layer.

Add clear view behind the UITextView and drop a shadow on it.

like image 82
AntonPalich Avatar answered Mar 09 '26 06:03

AntonPalich



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!