iosuitextviewrtf

Displaying Rich Text File in UITextView Causes Choppy/Slow Scrolling


Im currently loading a non-english (hebrew) Rich Text File into a UITextView like so.

self.textView.attributedText =
    [NSAttributedString.alloc
     initWithFileURL:[ NSBundle.mainBundle URLForResource:@"TextFile" withExtension:@"rtf"  ]
     options:nil
     documentAttributes:nil
     error:NULL
     ];

Everything get loaded correctly and the file scrolls, just it gets very choppy on the way down. I assume this is a rendering issue with UITextView.

Is there any other library or way to make the scrolling smooth. Note: The UITextView is non-editable and non-selectable already.


Solution

  • This may not be ideal, but I've had this idea work in similar situations. Try increasing the height of the UITextView(to create a sort of buffer). You may have to adjust the scrollIndicatorInsets, contentInsets, layer.zPosition of various UIView's, and possibly make the UITextView transparent with another UITextView behind it with the proper size/border/etc depending on your layout.

    Option 2

    UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(40, 100, 200, 100)];
    scrollView.scrollEnabled = YES;
    scrollView.contentInset = UIEdgeInsetsZero;
    [self.view addSubview:scrollView];
    
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, scrollView.bounds.size.width, HEIGHT)];
    label.text = @"text";
    label.numberOfLines = 0;
    [scrollView addSubview:label];
    scrollView.contentSize = CGSizeMake(label.bounds.size.width, label.bounds.size.height);