zoukankan      html  css  js  c++  java
  • 富文本及点击方法

    富文本及点击方法

    类似这种效果及功能。

    static NSString *const kStringTip = @"如有问题,请拨打客服电话:010-57512156";


    _tip = [[UITextView alloc] init]; _tip.width = SCREEN_WIDTH - kSideOffset * 2.0; _tip.text = kStringTip; [_tip sizeToFit]; _tip.top = labelY + 29; _tip.left = kSideOffset; _tip.delegate = self; [self.view addSubview:_tip]; NSString * creat = @"010-57512156"; NSString * showLabel = [NSString stringWithFormat:@"%@",kStringTip]; _tip.userInteractionEnabled = YES; NSMutableAttributedString *AttributedStr = [[NSMutableAttributedString alloc]initWithString:showLabel]; NSRange range = [showLabel rangeOfString:creat]; [AttributedStr addAttribute:NSForegroundColorAttributeName value:COLOR_GRAY3 range:NSMakeRange(range.location, range.length)];//字体颜色 [AttributedStr addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInteger:NSUnderlineStyleDouble] range:NSMakeRange(range.location, range.length)];//字加下划线 [AttributedStr addAttribute:NSLinkAttributeName value:@"tel://" range:NSMakeRange(range.location, range.length)];//加点击事件 _tip.attributedText = AttributedStr; _tip.editable = NO;//这个一定要设置 _tip.userInteractionEnabled = YES; _tip.textColor = COLOR_GRAY3;//在设置完富文本之后设置textview的字体颜色才会生效 _tip.font = [UIFont systemFontOfSize:12];//在设置完富文本之后设置textview的字体大小才会生效

    代理方法

    - (BOOL)textView:(UITextView *)textView shouldInteractWithURL:(NSURL *)URL inRange:(NSRange)characterRange {
        if ([[URL scheme] isEqualToString:@"tel"]){
            NSString *phoneNumber = [NSString stringWithFormat:@"telprompt://%@",@"010-57512156"];
            NSURL *url = [NSURL URLWithString:phoneNumber];
            if ([[UIApplication sharedApplication]canOpenURL:url]) {
                [[UIApplication sharedApplication]openURL:url];
            }
            return NO;
        }
        return YES;
    }
  • 相关阅读:
    web前端开发最佳实践--(笔记之JavaScript最佳实践)
    web前端开发最佳实践--(笔记一)
    HTML5及CSS3--freeCodeCamp(笔记一)
    javascript系列--函数(一)
    HTML5本地存储
    分享一些好用的设计网站
    .net面试问题总结
    ife_task10--弹性盒子
    WPF--搭建一个简单的demo
    信息技术文集
  • 原文地址:https://www.cnblogs.com/miaomiaocat/p/6133243.html
Copyright © 2011-2022 走看看