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:
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!