iOS 富文本点击事件
- #import "ViewController.h"
- #define font 17
- @interface ViewController ()<UITextViewDelegate>
- @property (weak, nonatomic) IBOutlet UITextView *textview;
- @property (assign, nonatomic) BOOL isSelect;
- @end
- @implementation ViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- [self protocolIsSelect:self.isSelect];
- }
- - (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;
- _textview.selectable = 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;
- }
- @end
iOS 富文本点击事件的更多相关文章
- textView富文本点击事件
NSDictionary * attDic = [NSDictionary dictionaryWithObjectsAndKeys:RGBCOLOR(31, 132, 204),NSForegrou ...
- iOS富文本组件的实现—DTCoreText源码解析 数据篇
本文转载 http://blog.cnbang.net/tech/2630/ DTCoreText是个开源的iOS富文本组件,它可以解析HTML与CSS最终用CoreText绘制出来,通常用于在一些需 ...
- app内嵌vue h5,安卓和ios拦截H5点击事件
安卓和ios拦截h5点击事件,这个函数事件必须是暴漏在window下的 安卓和ios拦截普通h5函数: <div onclick = "show(),window.android.sh ...
- iOS富文本
背景:前些天突然想做一个笔记本功能,一开始,觉得挺简单的呀,一个UITextView,网络缓存也不干了,直接本地NSUserDefault存储,然后完事了,美工,弄几张好看的图片,加几个动画,也就这样 ...
- iOS - 富文本
iOS--NSAttributedString超全属性详解及应用(富文本.图文混排) ios项目中经常需要显示一些带有特殊样式的文本,比如说带有下划线.删除线.斜体.空心字体.背景色.阴影以及图文 ...
- iOS - 富文本AttributedString
最近项目中用到了图文混排,所以就研究了一下iOS中的富文本,打算把研究的结果分享一下,也是对自己学习的一个总结. 在iOS中或者Mac OS X中怎样才能将一个字符串绘制到屏幕上呢? ...
- iOS - 富文本直接设置文字的字体大小和颜色
富文本效果图: 富文本实现代码: UILabel *orderSureLabel = [Common lableFrame:CGRectZero title:] textColor:[UIColor ...
- OS开发小记:iOS富文本框架DTCoreText在UITableView上的使用
要在页面中显示自己的布局,比如文字的字体和颜色.图文并排的样式,我们要用iOS SDK的原生UI在app本地搭建,如果一个页面需要在服务器端获取数据的话,我们也要在本地搭建好固定的布局,解析服务器传回 ...
- IOS微信浏览器点击事件不起作用问题
问题: $(document).on("click",".btn",function(){alert("1")}); 在微信浏览器上点击不起 ...
随机推荐
- S3C2440之IIC裸机驱动
花了两天的时间终于把这个搞定了,其实I2C的原理还是比较简单的,只是几个细节性的东西还是需要特别的注意,主要是需要注意一下几点: 1.rIICCON &= ~0x10; 清中断必须要在rIIC ...
- DB2使用存储过程插入数据
要求:插入一张表(TESTMV)中三个字段(ID, GROUPID[组id], USERID[用户id]),为了产生多个组,每个组多个人的数据,进行统计每个组多少人数据用 代码如下: delete t ...
- 绩效考核指标KPI 听课笔记
以前一直听人在说KPI,今天终于明白KPI是什么意思了!
- php处理金额显示的一些笔记
最近一直在做关于结算方面的需求,也熟悉了一些处理金额显示的方法,总结如下: 1.每三位数字以逗号分隔,比如1000 => 1,000. 可以直接使用number_format函数.eg:echo ...
- mysql 数据库 简单存储过程游标使用
BEGIN #Routine body goes here... DECLARE no_more_record INT DEFAULT 0; DECLARE TEST_ID INT(20); DECL ...
- 解决 jQuery.UI.Resizable aspectRatio在init后无法重新设置
一.背景 在jQuery1.9.x版本之前,存在aspectRatio在Resizable方法init之后,无法再次修改aspectRatio的boolean值. 二.解决方案 // 用于fix j ...
- Sql Server 日期格式化
select CONVERT(date,myDtae,23),ID from myFirstTable; http://www.cnblogs.com/hantianwei/archive/2009/ ...
- JSTL标签库--核心标签库
->JSTL的使用和EL表达式是分不开的 ->JSTL标签库分为5类 1.核心标签库(这里只介绍该标签库) 2.I18N格式化标签库 3.SQL标签库 4.XML标签库 5.函数标签库 - ...
- UVa 1395 Slim Span
问题:给出一个n结点的图,求最大边与最小边差值最小的生成树 my code: #include <iostream> #include <cstdio> #include &l ...
- PNG文件转png8
png8比普通png图片会小很多,所以在开发中为了是图片加载速度更快我们可以把Png图片都转成png8 首先添加 ImageProcessor 包 private byte[] ConvertTo ...