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. C#中Internal关键字的总结

    https://blog.csdn.net/baidu_32134295/article/details/51285603     版权声明:本文为博主原创文章,未经博主允许不得转载. https:/ ...

  2. d题

    #include<iostream>#include<algorithm>using namespace std;int a[200005];int b[200005];int ...

  3. 查看SQL SERVER Job details

    SELECT [sJOB].[job_id] AS [JobID] , [sJOB].[name] AS [JobName] , [sDBP].[name] AS [JobOwner] , [sCAT ...

  4. gitlab 邮件配置

    vim /etc/gitlab/gitlab.rb gitlab_rails['smtp_enable'] = true gitlab_rails['smtp_address'] = "sm ...

  5. 常见的几种web攻击方式

    一.Dos攻击(Denial of Service attack) 是一种针对服务器的能够让服务器呈现静止状态的攻击方式.有时候也加服务停止攻击或拒绝服务攻击.其原理就是发送大量的合法请求到服务器,服 ...

  6. c++ 封装线程库 2

    1.2线程回收: 首先得知道线程的两个状态: Joinable Detached 简单理解,如果一个线程是joinable的状态,那么这样的线程,就必须使用pthread_join来回收,否则程序结束 ...

  7. 那些经历过的Bug Unity的Invoke方法

    有一个游戏对象,上面挂着 3 个脚本,如下: using System.Collections; using System.Collections.Generic; using UnityEngine ...

  8. GridLayout(网格布局)

    常用属性: 排列对齐: ①设置组件的排列方式:  android:orientation=""     vertical(竖直,默认)或者horizontal(水平) ②设置组件的 ...

  9. (转)轻松掌握shell编程中数组的常见用法及示例

    缘起:在老男孩进行linux培训shell编程教学中,发现不少水平不错的网友及同学对数组仍然很迷糊,下面就给大家分享下数组的用法小例子,希望能给大家一点帮助.其实SHELL的数组很简单,好用.我们学习 ...

  10. jQuery属性选择器中加变量

    $(function () { $('#bkhandle').on('click','#bkdel',function () { $.ajax( { url:"{% url 'bkdel' ...