#import "ViewController.h"
@interface ViewController ()<UITextViewDelegate>
@property (nonatomic,strong) UITextView *textView;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(20, 100, self.view.bounds.size.width - 20, 44)];
textView.delegate = self;
textView.editable = NO;
textView.scrollEnabled = NO;
self.textView = textView;
NSMutableAttributedString *attr = [[NSMutableAttributedString alloc] initWithString:@"客服电话:400-775-5333 转4 (每天9:00-20:00)"];
[attr setAttributes:@{NSForegroundColorAttributeName:[UIColor blackColor],NSFontAttributeName:[UIFont systemFontOfSize:14]} range:NSMakeRange(0, attr.length)];
[attr setAttributes:@{NSForegroundColorAttributeName:[UIColor colorWithRed:0 green:147/255.0 blue:238/255.0 alpha:1],
NSFontAttributeName:[UIFont systemFontOfSize:14],
NSLinkAttributeName:@"dianji"}
range:NSMakeRange(5, 15)];
textView.attributedText = attr;
[self.view addSubview:textView];
}
#pragma mark **- 实现链接代理**
- (BOOL)textView:(UITextView *)textView shouldInteractWithURL:(NSURL *)URL inRange:(NSRange)characterRange interaction:(UITextItemInteraction)interaction {
if ([URL.absoluteString isEqualToString:@"dianji"]) {
NSLog(@"~~~~~~~~~~~~~~~");
}
return YES;
}
- (BOOL)textViewShouldBeginEditing:(UITextView *)textView {
return NO;
}
@end
