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")}); 在微信浏览器上点击不起 ...
随机推荐
- [置顶] Adapter详解
动态添加数据适配器adapter Adapter是适配器,许多UI组件需要搭配Adapter来显示界面,例如Spinner与ListView,另外当我们需要动态的添加数据给UI组件时就需要Adapte ...
- Android Apk获取包名和Activity名称
一.使用aapt(Android Asset Packaging Tool)工具获取: 1.配置Android环境: a.添加build-tools/android路径到系统环境变量的中Path中,注 ...
- eclipse安装svn插件的多种方式
方法一:在线安装 1.打开HELP->MyEclipse Configuration Center.切换到SoftWare标签页. 2.点击Add Site 打开对话框,在对话框Name输入Sv ...
- Java Volatile transient 关键字
随笔-204 评论-134 文章-0 trackbacks-0 Volatile修饰的成员变量在每次被线程访问时,都强迫从主内存中重读该成员变量的值.而且,当成员变量发生变化时,强迫线程将变 ...
- CKPlayer 只调用HTML5播放器时全屏问题 这只是Chrome浏览器的渲染bug
如题,在系统中使用CKPlayer播放器,一切顺利,偶然发现没有全屏按钮, 正常的全屏按钮是这样的: 经过一步步调试,发现问题出在iframe, 当视频页面在iframe内时,全屏按钮不显示了,这个和 ...
- Elasticsearch 5.0 磁盘空间节省策略的认识
前言:本文是当时QQ群员讨论磁盘空间如何优化,我搜了下类似的文章,结合官方文档做了一些总结 参考文章1 参考文章2 如果你有疑问,可以联系我参与讨论,或者去原文查看. NOTE: 磁盘空间节省问题,是 ...
- angularjs过滤器(一)------禁止转载------
如果用代码实现:将new Date()转换为 M/D/YY 00:00 格式. 启用过滤器有两种方式:①在HTML中用"|"启用过滤器.格式为{{$scope.property | ...
- python3的文件读写模式
任何一种语言,文件的读写都是非常常见的.python的文件读写非常简单,仅仅一个函数open(file也可以,但是我不常用). 先看看官网的解释: open(file, mode='r', buffe ...
- sql Cursor的用法
table1结构如下 id int name ) declare @id int ) declare cursor1 cursor for --定义游标cursor1 select * from ta ...
- Ubuntu 16.04 搭建Android开发环境
1.Installing Java sudo add-apt-repository ppa:webupd8team/java sudo apt-get update sudo apt-get inst ...