1. #import "ViewController.h"
  2.  
  3. #define font 17
  4. @interface ViewController ()<UITextViewDelegate>
  5. @property (weak, nonatomic) IBOutlet UITextView *textview;
  6. @property (assign, nonatomic) BOOL isSelect;
  7. @end
  8.  
  9. @implementation ViewController
  10.  
  11. - (void)viewDidLoad {
  12. [super viewDidLoad];
  13. [self protocolIsSelect:self.isSelect];
  14.  
  15. }
  16.  
  17. - (void)protocolIsSelect:(BOOL)select {
  18. NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:@"请遵守以下协议《支付宝协议》《微信协议》《建行协议》《招行协议》《中国银行协议》《上海银行协议》"];
  19. [attributedString addAttribute:NSLinkAttributeName
  20. value:@"zhifubao://"
  21. range:[[attributedString string] rangeOfString:@"《支付宝协议》"]];
  22. [attributedString addAttribute:NSLinkAttributeName
  23. value:@"weixin://"
  24. range:[[attributedString string] rangeOfString:@"《微信协议》"]];
  25. [attributedString addAttribute:NSLinkAttributeName
  26. value:@"jianhang://"
  27. range:[[attributedString string] rangeOfString:@"《建行协议》"]];
  28.  
  29. UIImage *image = [UIImage imageNamed:select == YES ? @"new_feature_share_true" : @"new_feature_share_false"];
  30. CGSize size = CGSizeMake(font + , font + );
  31. UIGraphicsBeginImageContextWithOptions(size, false, );
  32. [image drawInRect:CGRectMake(, , size.width, size.height)];
  33. UIImage *resizeImage = UIGraphicsGetImageFromCurrentImageContext();
  34. UIGraphicsEndImageContext();
  35. NSTextAttachment *textAttachment = [[NSTextAttachment alloc] init];
  36. textAttachment.image = resizeImage;
  37. NSMutableAttributedString *imageString = [NSMutableAttributedString attributedStringWithAttachment:textAttachment];
  38. [imageString addAttribute:NSLinkAttributeName
  39. value:@"checkbox://"
  40. range:NSMakeRange(, imageString.length)];
  41. [attributedString insertAttributedString:imageString atIndex:];
  42. [attributedString addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:font] range:NSMakeRange(, attributedString.length)];
  43. _textview.attributedText = attributedString;
  44. _textview.linkTextAttributes = @{NSForegroundColorAttributeName: [UIColor blueColor],
  45. NSUnderlineColorAttributeName: [UIColor lightGrayColor],
  46. NSUnderlineStyleAttributeName: @(NSUnderlinePatternSolid)};
  47.  
  48. _textview.delegate = self;
  49. _textview.editable = NO; //必须禁止输入,否则点击将弹出输入键盘
  50. _textview.scrollEnabled = NO;
  51.  
  52.     _textview.selectable = NO;
  1. }
  2.  
  3. - (BOOL)textView:(UITextView *)textView shouldInteractWithURL:(NSURL *)URL inRange:(NSRange)characterRange {
  4. if ([[URL scheme] isEqualToString:@"jianhang"]) {
  5. NSLog(@"建行支付---------------");
  6. return NO;
  7. } else if ([[URL scheme] isEqualToString:@"zhifubao"]) {
  8. NSLog(@"支付宝支付---------------");
  9. return NO;
  10. } else if ([[URL scheme] isEqualToString:@"weixin"]) {
  11. NSLog(@"微信支付---------------");
  12. return NO;
  13. } else if ([[URL scheme] isEqualToString:@"checkbox"]) {
  14. self.isSelect = !self.isSelect;
  15. [self protocolIsSelect:self.isSelect];
  16. return NO;
  17. }
  18. return YES;
  19. }
  20.  
  21. @end

iOS 富文本点击事件的更多相关文章

  1. textView富文本点击事件

    NSDictionary * attDic = [NSDictionary dictionaryWithObjectsAndKeys:RGBCOLOR(31, 132, 204),NSForegrou ...

  2. iOS富文本组件的实现—DTCoreText源码解析 数据篇

    本文转载 http://blog.cnbang.net/tech/2630/ DTCoreText是个开源的iOS富文本组件,它可以解析HTML与CSS最终用CoreText绘制出来,通常用于在一些需 ...

  3. app内嵌vue h5,安卓和ios拦截H5点击事件

    安卓和ios拦截h5点击事件,这个函数事件必须是暴漏在window下的 安卓和ios拦截普通h5函数: <div onclick = "show(),window.android.sh ...

  4. iOS富文本

    背景:前些天突然想做一个笔记本功能,一开始,觉得挺简单的呀,一个UITextView,网络缓存也不干了,直接本地NSUserDefault存储,然后完事了,美工,弄几张好看的图片,加几个动画,也就这样 ...

  5. iOS - 富文本

    iOS--NSAttributedString超全属性详解及应用(富文本.图文混排)   ios项目中经常需要显示一些带有特殊样式的文本,比如说带有下划线.删除线.斜体.空心字体.背景色.阴影以及图文 ...

  6. iOS - 富文本AttributedString

    最近项目中用到了图文混排,所以就研究了一下iOS中的富文本,打算把研究的结果分享一下,也是对自己学习的一个总结. 在iOS中或者Mac OS X中怎样才能将一个字符串绘制到屏幕上呢?         ...

  7. iOS - 富文本直接设置文字的字体大小和颜色

    富文本效果图: 富文本实现代码: UILabel *orderSureLabel = [Common lableFrame:CGRectZero title:] textColor:[UIColor ...

  8. OS开发小记:iOS富文本框架DTCoreText在UITableView上的使用

    要在页面中显示自己的布局,比如文字的字体和颜色.图文并排的样式,我们要用iOS SDK的原生UI在app本地搭建,如果一个页面需要在服务器端获取数据的话,我们也要在本地搭建好固定的布局,解析服务器传回 ...

  9. IOS微信浏览器点击事件不起作用问题

    问题: $(document).on("click",".btn",function(){alert("1")}); 在微信浏览器上点击不起 ...

随机推荐

  1. S3C2440之IIC裸机驱动

    花了两天的时间终于把这个搞定了,其实I2C的原理还是比较简单的,只是几个细节性的东西还是需要特别的注意,主要是需要注意一下几点: 1.rIICCON &= ~0x10; 清中断必须要在rIIC ...

  2. DB2使用存储过程插入数据

    要求:插入一张表(TESTMV)中三个字段(ID, GROUPID[组id], USERID[用户id]),为了产生多个组,每个组多个人的数据,进行统计每个组多少人数据用 代码如下: delete t ...

  3. 绩效考核指标KPI 听课笔记

    以前一直听人在说KPI,今天终于明白KPI是什么意思了!

  4. php处理金额显示的一些笔记

    最近一直在做关于结算方面的需求,也熟悉了一些处理金额显示的方法,总结如下: 1.每三位数字以逗号分隔,比如1000 => 1,000. 可以直接使用number_format函数.eg:echo ...

  5. mysql 数据库 简单存储过程游标使用

    BEGIN #Routine body goes here... DECLARE no_more_record INT DEFAULT 0; DECLARE TEST_ID INT(20); DECL ...

  6. 解决 jQuery.UI.Resizable aspectRatio在init后无法重新设置

    一.背景  在jQuery1.9.x版本之前,存在aspectRatio在Resizable方法init之后,无法再次修改aspectRatio的boolean值. 二.解决方案 // 用于fix j ...

  7. Sql Server 日期格式化

    select CONVERT(date,myDtae,23),ID from myFirstTable; http://www.cnblogs.com/hantianwei/archive/2009/ ...

  8. JSTL标签库--核心标签库

    ->JSTL的使用和EL表达式是分不开的 ->JSTL标签库分为5类 1.核心标签库(这里只介绍该标签库) 2.I18N格式化标签库 3.SQL标签库 4.XML标签库 5.函数标签库 - ...

  9. UVa 1395 Slim Span

    问题:给出一个n结点的图,求最大边与最小边差值最小的生成树 my code: #include <iostream> #include <cstdio> #include &l ...

  10. PNG文件转png8

    png8比普通png图片会小很多,所以在开发中为了是图片加载速度更快我们可以把Png图片都转成png8 首先添加  ImageProcessor  包 private byte[] ConvertTo ...