UITextView改变选中字的颜色
2016-04-22 15:51
176 查看
<pre name="code" class="objc">- (void)viewDidLoad { [super viewDidLoad]; UIMenuItem *menuItem = [[UIMenuItem alloc]initWithTitle:@"改变颜色" action:@selector(changeColor)]; [[UIMenuController sharedMenuController] setMenuItems:[NSArray arrayWithObjects:menuItem, nil]]; [[UIMenuController sharedMenuController] setTargetRect:self.textView.frame inView:self.view]; [[UIMenuController sharedMenuController] setMenuVisible:YES animated: YES]; // Do any additional setup after loading the view, typically from a nib. }
-(void)changeColor{ NSLog(@"改变颜色"); NSString *selectString = [self.textView.text substringWithRange:self.textView.selectedRange]; NSLog(@"选中文字为:%@",selectString); NSMutableAttributedString *abString = [[NSMutableAttributedString alloc]initWithAttributedString:self.textView.attributedText]; [abString addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:self.textView.selectedRange]; self.textView.attributedText = abString; }
相关文章推荐
- 利用STL中的队列queue对二叉树进行层遍历
- 【使用Modern UI快速开发WPF应用】
- Failed to set () user defined inspected property on (UIButton): [<UIButton 0x7fe5586efeb0> setValue:
- 启动图实现:UIScrollView+UIPageControl简单实现
- leetcode——334—— Increasing Triplet Subsequence
- 如何不让键盘挡住UITextField控件
- 转载/SOAP UI
- 关于UIView的三个容易混淆的属性,alpha,opaque,hide的简要说明
- UIWindow
- iOS开发UI篇—UIWindow简单介绍
- Qt Quick中的ListView
- 元素命名空间中的“MvcBuildViews”无效
- iOS小技巧-多个UIListView设置automaticallyAdjustsScrollViewInsets属性
- 转载/JSTL/attribute value does not accept any express
- iOS----自定义UIView,绘制一个UIView
- vue中的指令
- UISegmentedControl添加图片不显示的问题
- UI基本控件---UITextField
- UIButton中图片与文字的位置设置
- UILabel