I'm doing the same thing. Just add the button to textView.superView, because textView is scrollView. Use button's rect in textView as textView.textContainer.exclusionPaths = [UIBezierPath(rect: rect)]
At last, I did it. Most important thing is rect must be included in textView.frame.