大佬教程收集整理的这篇文章主要介绍了UITextView文本选择和在iOS 8中突出显示跳跃,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
> UITextView中的Setected文本,具有用户可用的突出显示功能:
> UITextView中突出显示的文本,使用新的背景颜色,用户在点击突出显示功能后选择:
在iOS 7中,以下代码可以完美地完成此任务:
- (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; }
但是在iOS 8中,文本选择正在跳跃.当我使用UIMenuItem和UIMenuController中的突出显示功能时,它也会跳转到另一个UITextView偏移量.
如何在iOS 8中解决此问题?
- (void)viewDidLoad { [super viewDidLoad]; UIMenuItem *highlightMenuItem = [[UIMenuItem alloc] initWithtitle:@"Highlight" action:@SELEctor(highlight)]; [[UIMenuController sharedMenuController] setMenuItems:[NSArray arrayWithObject:highlightMenuItem]]; float sysVer = [[[UIDevice currentDevice] systemVersion] floatValue]; if (sysVer >= 8.0) { self.textView.layoutManager.allowsnonContiguousLayout = NO; } } - (void)highlight { NSRange SELEctedTextRange = self.textView.SELEctedRange; [attributedString addAttribute:NSBACkgroundColorAttributename value:[UIColor redColor] range:SELEctedTextRange]; float sysVer = [[[UIDevice currentDevice] systemVersion] floatValue]; if (sysVer < 8.0) { // iOS 7 fix self.textView.scrollEnabled = NO; self.textView.attributedText = attributedString; self.textView.scrollEnabled = YES; } else { self.textView.attributedText = attributedString; } }
以上是大佬教程为你收集整理的UITextView文本选择和在iOS 8中突出显示跳跃全部内容,希望文章能够帮你解决UITextView文本选择和在iOS 8中突出显示跳跃所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。