2

I'm have a problem with exclusionPaths when a textView has new line characters:

Here is my code:

- (void)viewDidLoad
{
  [super viewDidLoad];
  UIView *view = [[UIView alloc] init];
  UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(0, 333, 360, 480)];
  view.frame = CGRectMake(50, 0, 50, 50);
  view.backgroundColor = [UIColor blackColor];
  NSLog(@"%@", NSStringFromCGRect(view.frame));
  [textView addSubview:view];

  CGRect relativeRect = [textView convertRect:view.bounds fromView:view];

  UIBezierPath *bezierPath = [UIBezierPath bezierPathWithRect:relativeRect];
  textView.text = @"asddsaadasddsasdasdjsdhfjkdhkjdhfgjkldhsgfjlk\n\nhfdsgjklhdfsljkghdklfjgshdgjklfshdfgjklhfglkjdshjklgfdshjklgdfshkljfdsghfjkldghlkjfdghskljgdfhslkjgdfshjklgfdshjkgfdshlkjgdfhskljdgfhsjklgdhsjklfgdshjkglfdshjklgfdshlkjfgdhjklgdfshjdfkslghkjfdlsghjkldsfghjkhdfsgkjlhjgkldfshgdflksjhfdksgjhdfkjlgshfkljdshgjkdfhskjglhdfsjkghdfkjglhdsfkjghkljdfhgkjlhdsfkjlghjkldsfghjklhgsfdjklhgsdfkjlghdsfklgfdhsklg";
  textView.textContainer.exclusionPaths = @[bezierPath];
  [self.view addSubview:textView];

}

And here is the result:

enter image description here

The problem being that the new line characters make the exclusionPaths bigger than they should be. The issue is also described here: Newlines in iOS 7 UITextView breaking Text Kit exclusion zone wrapping, but it shows how to fix this iOS 7 bug if using Interface Builder to create the UITextView. How would I fix this programatically? Thanks!

Community
  • 1
  • 1
Byron Duenas
  • 161
  • 1
  • 8

2 Answers2

5

So the winning property to disable is "scrollEnabled":

textView.editable = NO
textView.scrollEnabled = NO

The above code fixes my issues with exclusionPaths

Byron Duenas
  • 161
  • 1
  • 8
0

Try to use this in subclass of TextView if you need editable textView

 - (void)layoutSubviews
{
[super layoutSubviews];

self.contentOffset = CGPointMake(0, 0);
Igor Bizi
  • 105
  • 10