-1

I am using UITextView to display the NSAttributedString (Which Contains NSTextAttachment and HTML tables using NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType).

When I scrolling the UITextView at half of the screen the texts are disappearing. enter image description here Can any one explain how it happens? and how to resolve it?

UITextView *textView = [[UITextView alloc]init];
textView.frame = CGRectMake(0, 0, 768, 1024);
textView.editable = NO;
textView.selectable = NO;
textView.attributedText = attributedString; //My AttributedSting
[self.view addSubview:textView];
Manimaran
  • 465
  • 2
  • 10

2 Answers2

0

This is probably because of incorrect size of the textview frame. Change the background colour of the textview to see if the frame has been set appropriately.

Kunal Shah
  • 104
  • 5
0

Try making sure no constraints are created automatically by adding:

[textView setTranslatesAutoresizingMaskIntoConstraints:NO];

Ideally you would be best to use constraints so that the text view is pinned on its leading edge and trailing edge to the containing view and on its bottom edge and top edge to the bottom layout guide and top layout guide respectively.

Rory McKinnel
  • 7,936
  • 2
  • 17
  • 28
  • Where are you adding the text view in your code? Also it might be worth making the background color red say and printing out the frame in `viewDidAppear` to see what actual frame it is using. Also have you added any other views which could be covering the bottom of the screen? – Rory McKinnel Apr 20 '15 at 13:11
  • You could also try using the 3D exploded view in the simulator which will show you the view layers in depth order. If you have not used this before, it is activated by pressing the symbol on the debugger when running which looks like a cross made from two rectangles: one over the other. The exploded view will show you where all your views are. – Rory McKinnel Apr 20 '15 at 13:18
  • You understands my question wrongly. The texts are showing full screen initially. When I scrolling to end of the document the text are disappearing in half way mark. You can see it in my screenshot, where the scroll bar is visibile – Manimaran Apr 21 '15 at 05:21
  • Does the scroll bar go all the way to the bottom or just half way? – Rory McKinnel Apr 21 '15 at 06:32
  • It goes all the way to the bottom – Manimaran Apr 21 '15 at 06:33
  • I noticed on a few sites that some code sets scrolling to NO, then sets the attributed text, then sets scrolling to YES. So: `textView.scrollEnabled = NO; textView.attributedText = attributedString; textView.scrollEnabled = YES;` – Rory McKinnel Apr 21 '15 at 10:12
  • Perhaps also try adding it as a subview "before" you set the text and other properties. – Rory McKinnel Apr 21 '15 at 10:15
  • Both are not working. When I tried this `textView.scrollEnabled = NO; textView.attributedText = attributedString; textView.scrollEnabled = YES; ` the textview not scrolling – Manimaran Apr 21 '15 at 10:56
  • This looks similar to you issue. Worth a look. http://stackoverflow.com/questions/16836707/uitextview-text-cut-off-when-there-is-a-large-amount-of-text – Rory McKinnel Apr 21 '15 at 11:56