hanumanDev
hanumanDev

Reputation: 6614

Text scrolls outside of the UITextView box boundary

I have a UITextView that has some text in it. The problem is that the text scrolls outside of the boundaries of the UITextView box. (The UITextView is uneditable.)

here's the code and what I have tried to resolve this issue:

  - (void)viewDidLoad {

        textBG.contentInset = UIEdgeInsetsZero;

    //  textBG.layer.masksToBounds = NO;
        textBG.layer.cornerRadius = 10.0;
        textBG.layer.borderWidth = 0.0;
        [textBG setClipsToBounds:YES];

    [super viewDidLoad];
}

- (void)textViewDidBeginEditing:(UITextView*)textView
{

textBG.contentInset = UIEdgeInsetsZero;    
 [textBG setClipsToBounds:YES];   
}

- (void) shouldChangeTextInRange:(UITextView*)textView {

    textBG.contentInset = UIEdgeInsetsZero;    
    [textBG setClipsToBounds:YES];

}

thanks for any help

enter image description here

Upvotes: 15

Views: 4738

Answers (4)

Manish Mahajan
Manish Mahajan

Reputation: 2082

Just put this one line code to solve problem.

yourTextView.clipsToBounds = true

Upvotes: 1

Najam
Najam

Reputation: 1159

I faced this same problem, so I track down the source ... this is because of while adding shadow somehow you disturbed it's masksToBounds property. Therefore, while adding more text it got overflowed. Simple solution which I found is to write this simple line after adding shadow.

[self.myTextView setClipsToBounds:YES];

usually should be in viewDidLoad method, but remember to write this line only after applying shadow.

Thanks for reading this.

Upvotes: 0

Loquatious
Loquatious

Reputation: 1775

Try to change in XIB for your TextView like below:enter image description here

Upvotes: 2

Narayana Rao Routhu
Narayana Rao Routhu

Reputation: 6323

write this in textView delegate methods like textViewDidBeginEditing

textBG.contentInset = UIEdgeInsetsZero;

in viewDidload

[textBG setClipsToBounds:YES];

Upvotes: 20

Related Questions