如何修改文本消息中的超链接的颜色

如何修改文本消息中的超链接和电话号码的颜色
发布时间: 2017-08-09 10:10

回答:


示例代码:

- (void)willDisplayMessageCell:(RCMessageBaseCell *)cell atIndexPath:(NSIndexPath *)indexPath {
     
     if([cell isKindOfClass:[RCTextMessageCell class]]){
       
          RCTextMessageCell *txtCell = (RCTextMessageCell *)cell;
          
          txtCell.textLabel.attributeDictionary = 
                                                 @{     
                                                    @(NSTextCheckingTypeLink) : @{NSForegroundColorAttributeName : [UIColor redColor]},
                                                    @(NSTextCheckingTypePhoneNumber) : @{NSForegroundColorAttributeName : [UIColor redColor]} 
                                                  };
                                                  
          txtCell.textLabel.highlightedAttributeDictionary = 
                                                         @{
                                                            @(NSTextCheckingTypeLink) : @{NSForegroundColorAttributeName : [UIColor redColor]},  
                                                            @(NSTextCheckingTypePhoneNumber) : @{NSForegroundColorAttributeName : [UIColor redColor]
                                                          };
    }
 }