I'm using UIMenuItem and UIMenuController to add a highlight feature to my UITextView, so the user can change the background color of the selected text, as shown in the pictures bellow:
- Setected text in
UITextViewwith the highlight feature available to the user:

- Highlighted text in
UITextViewwith a new background color, chosen by the user after tapping on the highlight feature:
In iOS 7 the following code is working perfectly to accomplish this task:
- (void)viewDidLoad {
[super viewDidLoad];
UIMenuItem *highlightMenuItem = [[UIMenuItem alloc] initWithTitle:@"Highlight" action:@selector(highlight)];
[[UIMenuController sharedMenuController] setMenuItems:[NSArray arrayWithObject:highlightMenuItem]];
}
- (void)highlight {
NSRange selectedTextRange = self.textView.selectedRange;
[attributedString addAttribute:NSBackgroundColorAttributeName
value:[UIColor redColor]
range:selectedTextRange];
// iOS 7 fix, NOT working in iOS 8
self.textView.scrollEnabled = NO;
self.textView.attributedText = attributedString;
self.textView.scrollEnabled = YES;
}
But in iOS 8 the text selection is jumping. When I use the highlight feature from the UIMenuItem and UIMenuController it jumps also to another UITextView offset.
How do I solve this problem in iOS 8?