iOS 富文本点击事件
来源:互联网 发布:阿里巴巴网络银行 编辑:程序博客网 时间:2024/05/16 13:56
1 #import "ViewController.h" 2 3 #define font 17 4 @interface ViewController ()<UITextViewDelegate> 5 @property (weak, nonatomic) IBOutlet UITextView *textview; 6 @property (assign, nonatomic) BOOL isSelect; 7 @end 8 9 @implementation ViewController10 11 12 - (void)viewDidLoad {13 [super viewDidLoad];14 [self protocolIsSelect:self.isSelect];15 16 }17 18 - (void)protocolIsSelect:(BOOL)select {19 NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:@"请遵守以下协议《支付宝协议》《微信协议》《建行协议》《招行协议》《中国银行协议》《上海银行协议》"];20 [attributedString addAttribute:NSLinkAttributeName21 value:@"zhifubao://"22 range:[[attributedString string] rangeOfString:@"《支付宝协议》"]];23 [attributedString addAttribute:NSLinkAttributeName24 value:@"weixin://"25 range:[[attributedString string] rangeOfString:@"《微信协议》"]];26 [attributedString addAttribute:NSLinkAttributeName27 value:@"jianhang://"28 range:[[attributedString string] rangeOfString:@"《建行协议》"]];29 30 31 UIImage *image = [UIImage imageNamed:select == YES ? @"new_feature_share_true" : @"new_feature_share_false"];32 CGSize size = CGSizeMake(font + 2, font + 2);33 UIGraphicsBeginImageContextWithOptions(size, false, 0);34 [image drawInRect:CGRectMake(0, 2, size.width, size.height)];35 UIImage *resizeImage = UIGraphicsGetImageFromCurrentImageContext();36 UIGraphicsEndImageContext();37 NSTextAttachment *textAttachment = [[NSTextAttachment alloc] init];38 textAttachment.image = resizeImage;39 NSMutableAttributedString *imageString = [NSMutableAttributedString attributedStringWithAttachment:textAttachment];40 [imageString addAttribute:NSLinkAttributeName41 value:@"checkbox://"42 range:NSMakeRange(0, imageString.length)];43 [attributedString insertAttributedString:imageString atIndex:0];44 [attributedString addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:font] range:NSMakeRange(0, attributedString.length)];45 _textview.attributedText = attributedString;46 _textview.linkTextAttributes = @{NSForegroundColorAttributeName: [UIColor blueColor],47 NSUnderlineColorAttributeName: [UIColor lightGrayColor],48 NSUnderlineStyleAttributeName: @(NSUnderlinePatternSolid)};49 50 _textview.delegate = self;51 _textview.editable = NO; //必须禁止输入,否则点击将弹出输入键盘52 _textview.scrollEnabled = NO;53 }54 55 - (BOOL)textView:(UITextView *)textView shouldInteractWithURL:(NSURL *)URL inRange:(NSRange)characterRange {56 if ([[URL scheme] isEqualToString:@"jianhang"]) {57 NSLog(@"建行支付---------------");58 return NO;59 } else if ([[URL scheme] isEqualToString:@"zhifubao"]) {60 NSLog(@"支付宝支付---------------");61 return NO;62 } else if ([[URL scheme] isEqualToString:@"weixin"]) {63 NSLog(@"微信支付---------------");64 return NO;65 } else if ([[URL scheme] isEqualToString:@"checkbox"]) {66 self.isSelect = !self.isSelect;67 [self protocolIsSelect:self.isSelect];68 return NO;69 }70 return YES;71 }72 73 74 @end
0 0
- iOS 富文本点击事件
- iOS富文本设置样式,插入图片,点击事件
- 富文本点击事件(链接)
- iOS 之富文本可点击
- iOS UILabel网址识别添加点击事件及以富文本形式显示
- Android富文本实现不同的文字添加点击事件
- ios 富文本编辑器
- iOS之富文本
- iOS之富文本
- ios之富文本
- iOS之富文本
- iOS之富文本
- iOS 富文本 AttributedString
- IOS-富文本
- iOS之富文本
- ios 富文本
- iOS AttributeString(富文本)
- iOS之富文本
- linux下如何实现mysql数据库每天自动备份定时备份
- 文章标题
- 弄明白Android 接口回调机制
- CAD绘图控件VectorDraw web library (javascript) v7.7010.1.0版本更新
- Caffe学习系列(5):其它常用层及参数
- iOS 富文本点击事件
- PHP中使用ActiveMQ实现消息队列
- 线程池ExecutorService
- ToggleButton控件的使用
- C++模板
- iOS去掉导航栏底部的线
- Java笔试中遇见奇怪问题积累篇
- hadoop集群搭建
- 洛谷P2322 [HNOI2006]最短母串问题