Using an exclusion path with a UITextView is not properly wrapping the words for the first and last line in the example shown (lower example). It does render properly using word-wrap with CoreText (top example image).
Here is the code for the UITextView (both use the same size bezier path, and both use the same font and paragraph settings)
NSString *testText = @"Text Kit exclusion paths ..."; //text truncated for brevity
UIBezierPath *viewPath = [UIBezierPath bezierPathWithRect:CGRectMake(0, 0, 280, 280)];
UIBezierPath *shapePath = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(10, 10, 265, 265)];
viewPath.usesEvenOddFillRule = true;
shapePath.usesEvenOddFillRule = true;
[shapePath appendPath:viewPath];
NSMutableAttributedString *title = [[NSMutableAttributedString alloc]initWithString:testText];
UIFont *font = [UIFont fontWithName:@"BradleyHandITCTT-Bold" size:14];
[title addAttribute:NSFontAttributeName value:font range:NSMakeRange(0, title.length)];
//add color
[title addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(0, title.length)];
//add alignment
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
[paragraphStyle setAlignment:NSTextAlignmentCenter];
[paragraphStyle setLineBreakMode:NSLineBreakByWordWrapping];
[title addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, title.length)];
UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(0.0, 370.0, 280, 280)];
textView.textContainerInset = UIEdgeInsetsMake(0,0,0,0);
textView.textContainer.exclusionPaths = @[shapePath];
[textView.textContainer setLineBreakMode:NSLineBreakByWordWrapping];
textView.contentInset = UIEdgeInsetsMake(0,0,0,0);
textView.attributedText = title;
textView.backgroundColor = [UIColor clearColor];
It is worth noting that the Text Kit is respecting the word wrapping rules except for the first and (possibly last) line where the text does not actually fit. I need this to work with a UITextView because text entry is required, or I would be done with my Core Text example. Swift answers are acceptable as well as obj-c.
How can I make UIKIt behave as it does with Core Text, or in other words properly word wrap all of the words in the example path provided?