textview上的富文本支持 文字,图片的点击事件

- (void)protocolIsSelect:(BOOL)select {
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:@"请遵守以下协议《支付宝协议》《微信协议》《建行协议》《招行协议》《中国银行协议》《上海银行协议》"];
[attributedString addAttribute:NSLinkAttributeName
value:@"zhifubao://"
range:[[attributedString string] rangeOfString:@"《支付宝协议》"]];
[attributedString addAttribute:NSLinkAttributeName
value:@"weixin://"
range:[[attributedString string] rangeOfString:@"《微信协议》"]];
[attributedString addAttribute:NSLinkAttributeName
value:@"jianhang://"
range:[[attributedString string] rangeOfString:@"《建行协议》"]]; UIImage *image = [UIImage imageNamed:select == YES ? @"new_feature_share_true" : @"new_feature_share_false"];
CGSize size = CGSizeMake(font + , font + );
UIGraphicsBeginImageContextWithOptions(size, false, );
[image drawInRect:CGRectMake(, , size.width, size.height)];
UIImage *resizeImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSTextAttachment *textAttachment = [[NSTextAttachment alloc] init];
textAttachment.image = resizeImage;
NSMutableAttributedString *imageString = [NSMutableAttributedString attributedStringWithAttachment:textAttachment];
[imageString addAttribute:NSLinkAttributeName
value:@"checkbox://"
range:NSMakeRange(, imageString.length)];
[attributedString insertAttributedString:imageString atIndex:];
[attributedString addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:font] range:NSMakeRange(, attributedString.length)];
_textview.attributedText = attributedString;
_textview.linkTextAttributes = @{NSForegroundColorAttributeName: [UIColor blueColor],
NSUnderlineColorAttributeName: [UIColor lightGrayColor],
NSUnderlineStyleAttributeName: @(NSUnderlinePatternSolid)}; _textview.delegate = self;
_textview.editable = NO; //必须禁止输入,否则点击将弹出输入键盘
_textview.scrollEnabled = NO;
} - (BOOL)textView:(UITextView *)textView shouldInteractWithURL:(NSURL *)URL inRange:(NSRange)characterRange {
if ([[URL scheme] isEqualToString:@"jianhang"]) {
NSLog(@"建行支付---------------");
return NO;
} else if ([[URL scheme] isEqualToString:@"zhifubao"]) {
NSLog(@"支付宝支付---------------");
return NO;
} else if ([[URL scheme] isEqualToString:@"weixin"]) {
NSLog(@"微信支付---------------");
return NO;
} else if ([[URL scheme] isEqualToString:@"checkbox"]) {
self.isSelect = !self.isSelect;
[self protocolIsSelect:self.isSelect];
return NO;
}
return YES;
}

在简书看到的,来源于:http://www.jianshu.com/p/480db0cc7380

富文本 文字图片点击,(TextView)的更多相关文章

  1. iOS开发富文本制作 图片和文字/NSMutableParagraphStyle/NSMutableAttributedString

    /NSMutableParagraphStyle/NSMutableAttributedString 组合使 NSString * titlestr=@"日产GT-R"; NSMu ...

  2. YYLabel 自动布局 富文本文字点击事件

    YYLabel显示多行除了需要设置numberOfLines = 0以外,还需要设置preferredMaxLayoutWidth最大的宽度值才可以生效多行效果 YYLabel中的NSMutableA ...

  3. wxParse解析富文本内容使点击图片可以选中并实现放大缩小

    wxParse解析富文本内容不多说,之前写过步骤介绍,主要是在使用过程中发现解析的富文本内容里有图片时有的可以点击放大缩小,有的点击却报错,找不到imgUrls. 经过排查发现:循环解析的富文本内容正 ...

  4. react-quill 富文本编辑器 ---- 图片处理

    import React,{Component} from 'react'; import ReactQuill,{ Quill } from 'react-quill'; import 'react ...

  5. 使用vue-quill-editor富文本 实现图片上传

    1. 下载并引入 import { quillEditor, Quill } from "vue-quill-editor"; import { container, ImageE ...

  6. kindeditor 富文本粘贴 图片

    <script type="text/javascript" src="../../Scripts/Plugins/kindeditor/kindeditor.js ...

  7. 使用KindEditor富文本编辑器,点击批量上传按钮没有选择图片按钮

    问题:批量上传没有选择图片按钮

  8. Kindeditor JS 富文本编辑器图片上传指定路径

    js //================== KindEditor.ready(function (K) { var hotelid = $("#hotelid").val(); ...

  9. php将富文本内容图片上传到oss并替换

    /** * php 提取html中图片并替换 */ //要替换的内容 //提取图片路径的src的正则表达式 $match_str = '/(<img([^>]*)\s*src=(\'|\& ...

随机推荐

  1. $('#').formValidation校验网址

    $('#addCarouselInfoForm').formValidation({ message: '格式不正确', //不忽略隐藏域验证 excluded: [], icon: { valid: ...

  2. Microsoft使用技巧

    1.拍摄屏幕内容的截图 按 Win + Shift + S 以打开截图栏,然后将光标拖动到要捕获的区域. 截图区域将保存到剪贴板. 2.使用键盘添加表情符号 随心随处表达自我. 按 Ctrl + Sh ...

  3. Head First 设计模式笔记(模版方法模式)

    1.定义: 在一个方法中定义一个算法骨架,而将一些步骤延迟到子类中.模版方法使得子类可以在不改变算法结构的情况下,重新定义算法中的某些步骤. 2.类图:  3.说明: 模版方法可以理解为一个方法里面包 ...

  4. Android Studio CMake依赖第三方库

    这里实现一个简单的功能在APP里调用libnative-lib.so里的add.libnative-lib.so去调用libthird.so里的third_add来实现 JniUtil public ...

  5. Python + Selenium 基础篇 - 打开和关闭浏览器

    1.首先要下载浏览器对应的driver,并放到你的python安装目录 Chrome浏览器(chromedriver): http://npm.taobao.org/mirrors/chromedri ...

  6. Beam内置的数据源清单(Java、Python)

    不多说,直接上干货! Beam内置的Java数据源清单: Beam内置的Python数据源清单:  

  7. eureka的一点细节

    第二部分粗略的过一遍,还是有些模糊,再来相对系统的看一下: ---------------------------------------------------------------------- ...

  8. ruby逻辑判断符号

    puts true and false  #相当于 (puts true) and false Use &&/|| for boolean expressions, and/or fo ...

  9. 如何解决css和js的{}与smarty定界符冲突的问题

    当输入url地址后网页出现:Fatal error: Uncaught exception 'SmartyCompilerException' with message 'Syntax Error i ...

  10. 搭建MHA

    安装MySQL 5.7 yum源的配置文件如下 [mysql57-community] name=MySQL 5.7 Community Server baseurl=http://repo.mysq ...