zoukankan      html  css  js  c++  java
  • 富文本 文字图片点击,(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 + 2, font + 2);
        UIGraphicsBeginImageContextWithOptions(size, false, 0);
        [image drawInRect:CGRectMake(0, 2, 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(0, imageString.length)];
        [attributedString insertAttributedString:imageString atIndex:0];
        [attributedString addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:font] range:NSMakeRange(0, 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

  • 相关阅读:
    利用表格分页显示数据的js组件datatable的使用
    css和javascript代码写在页面中的位置说明
    jqueryui组件progressbar进度条和日期组件datepickers的简单使用
    漏洞扫描工具Nessu的安装和简单使用
    jqueryui插件slider的简单使用
    html常用标签表单和表格等及css的简单入门
    通过flask实现web页面简单的增删改查bootstrap美化版
    jquery简单使用入门
    bootstrap简单使用布局、栅格系统、modal标签页等常用组件入门
    Centos7.3_x86_64通过systemctl控制tomcat8.0.46启动和停止
  • 原文地址:https://www.cnblogs.com/liuwenqiang/p/7126132.html
Copyright © 2011-2022 走看看