_tipTextView = [[UITextView alloc] init];
_tipTextView.delegate = self;
_tipTextView.editable = NO; //必须禁止输入,否则点击将弹出输入键盘
_tipTextView.scrollEnabled = NO;
_tipTextView.backgroundColor = [UIColor clearColor];
NSString *titleString = @"注:灰色区域只有VIP用户可抽取";
NSString *tapString = @"点击成为VIP";
NSMutableAttributedString *titleAttriString = [[NSMutableAttributedString alloc] initWithString:titleString];
NSMutableAttributedString *tapAttriString = [[NSMutableAttributedString alloc] initWithString:tapString];
NSRange selectedRange = {0, [tapAttriString length]};
[tapAttriString beginEditing];
// [tapAttriString addAttribute:NSUnderlineStyleAttributeName
// value:[NSNumber numberWithInt:NSSingleUnderlineStyle] // 添加下化线
// range:selectedRange];
[tapAttriString addAttribute:NSLinkAttributeName
value:@”vip://”
range:selectedRange];
// [tapAttriString setAttributes:@{NSForegroundColorAttributeName:[UIColor colorWithSelected], NSLinkAttributeName:[NSURL URLWithString:@”vip://”] } range:selectedRange];
// [tapAttriString addAttribute:NSForegroundColorAttributeName
// value:[UIColor colorWithSelected] // 更改颜色
// range:selectedRange];
[tapAttriString addAttribute:NSFontAttributeName
value:[UIFont systemFontOfSize:15]
range:selectedRange];
[titleAttriString addAttribute:NSFontAttributeName
value:[UIFont systemFont_13]
range:NSMakeRange(0, titleAttriString.length)];
[titleAttriString addAttribute:NSForegroundColorAttributeName
value:[UIColor whiteColor] // 更改颜色
range:NSMakeRange(0, titleAttriString.length)];
[tapAttriString endEditing];
[titleAttriString appendAttributedString:tapAttriString];
[_tipTextView setAttributedText:titleAttriString];
[_tipTextView sizeToFit];
_tipTextView.linkTextAttributes = @{NSForegroundColorAttributeName:[UIColor colorWithSelected]};//设置linkTextAttributes颜色
- (BOOL)textView:(UITextView )textView shouldInteractWithURL:(NSURL )URL inRange:(NSRange)characterRange {
if ([[URL scheme] isEqualToString:@”vip”]) {
NSLog(@”vip点击”);
return NO;
}
return YES;
}