富文本 文字图片点击,(TextView)
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)的更多相关文章
- iOS开发富文本制作 图片和文字/NSMutableParagraphStyle/NSMutableAttributedString
/NSMutableParagraphStyle/NSMutableAttributedString 组合使 NSString * titlestr=@"日产GT-R"; NSMu ...
- YYLabel 自动布局 富文本文字点击事件
YYLabel显示多行除了需要设置numberOfLines = 0以外,还需要设置preferredMaxLayoutWidth最大的宽度值才可以生效多行效果 YYLabel中的NSMutableA ...
- wxParse解析富文本内容使点击图片可以选中并实现放大缩小
wxParse解析富文本内容不多说,之前写过步骤介绍,主要是在使用过程中发现解析的富文本内容里有图片时有的可以点击放大缩小,有的点击却报错,找不到imgUrls. 经过排查发现:循环解析的富文本内容正 ...
- react-quill 富文本编辑器 ---- 图片处理
import React,{Component} from 'react'; import ReactQuill,{ Quill } from 'react-quill'; import 'react ...
- 使用vue-quill-editor富文本 实现图片上传
1. 下载并引入 import { quillEditor, Quill } from "vue-quill-editor"; import { container, ImageE ...
- kindeditor 富文本粘贴 图片
<script type="text/javascript" src="../../Scripts/Plugins/kindeditor/kindeditor.js ...
- 使用KindEditor富文本编辑器,点击批量上传按钮没有选择图片按钮
问题:批量上传没有选择图片按钮
- Kindeditor JS 富文本编辑器图片上传指定路径
js //================== KindEditor.ready(function (K) { var hotelid = $("#hotelid").val(); ...
- php将富文本内容图片上传到oss并替换
/** * php 提取html中图片并替换 */ //要替换的内容 //提取图片路径的src的正则表达式 $match_str = '/(<img([^>]*)\s*src=(\'|\& ...
随机推荐
- about rand and reflect
select regexp_replace(reflect("java.util.UUID", "randomUUID"), "-", &q ...
- vue父子组件通信(prop)
先定义子组件,注册prop接收父组件传递的值 <template> <div> <div>{{message}}(子组件)</div> </div ...
- spring boot——常用注解
@SpringBootApplication:申明让spring boot自动给程序进行必要的配置,这个配置等同于:@Configuration ,@EnableAutoConfiguration 和 ...
- oracle 12.1.0.2的mgmt 导致的ORA-01017 bug
两节点12c RAC,在两节点上export ORACLE_SID再sqlplus / as sysdba都正常登录,然而Commvault通过service_name方式(sqlplus sys/p ...
- Linux文件操作常用选项
常用选项 选项 功能 -a 查看隐藏文件 -l 列表方式查看 -h 人性化显示 * 通配符,忽略多个字符匹配 ? 通配符,忽略一个字符匹配 [Num1-Num2] 通配符,查看从Num1到Num2的匹 ...
- Maven 错误 Failure to transfer ...was cached in the local repository...
Maven 错误 Failure to transfer ...was cached in the local repository... 我解决的时候多了两步才解决 1. mvn clean ins ...
- UGUI 用手柄或者键盘控制选择Scroll View中的游戏对象时,滚动条跟着移动
原预制体以及脚本的下载地址:https://download.csdn.net/download/qq_15017279/10404010 1.新建一个Scroll View,删掉横向的滚动条,并且把 ...
- android 中百度地图 关于地图缩放所调用的事件
在做百度地图的时候 javascript 有个地图缩放的事件 但是在android 的API里面却没有,但是还好 官方给了一个MapStatusChangeListener,是这样介绍的 百度地图S ...
- Python 科学工具笔记
Python 科学工具笔记 numpy a = numpy.array([1,2,3,4]);// 创建一个numpy的数组对象 此时a.shape显示的值为(4,); 由此得出结论在一维的数组中, ...
- mysql关闭严格模式
通过配置文件修改: linux找my.cnf文件 window的修改办法是找my.ini sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES ub ...