1

In my iOS app, I am trying to add shadows to a UITextView using QuartzCore, but I end up with text scrolling outside of the bounds of the UITextView:

enter image description here

I have tried to use the solutions at Text scrolls outside of the UITextView box boundary, however none of the solutions worked. The first solution, textView.contentInset = UIEdgeInsetsZero;, does absolutely nothing to the UITextView when I place it in the viewDidLoad method. The second solution gets rid of the shadow that I'm trying to add: [textView setClipsToBounds:YES];.

Here is the Quartz Core code I'm using to create the shadow:

textView.layer.masksToBounds = NO;
textView.layer.shadowOffset = CGSizeMake(-1, 1);
textView.layer.shadowRadius = 3;
textView.layer.shadowOpacity = 0.3;

What am I doing wrong? Is this a bug in iOS? If so, are there any workarounds or solutions?

Community
  • 1
  • 1
Sam Spencer
  • 8,492
  • 12
  • 76
  • 133
  • Possible duplicate of [Text scrolls outside of the UITextView box boundary](https://stackoverflow.com/questions/7607907/text-scrolls-outside-of-the-uitextview-box-boundary) – Najam Mar 08 '18 at 06:42

1 Answers1

0

You can use this for get content size :

textView.frame = CGRectMake(0, 0, textView.contentSize.width, textView.contentSize.height);
VivienCormier
  • 1,133
  • 1
  • 11
  • 16