NSAttributedString+MLLabel.h 1016 B

1234567891011121314151617181920212223242526
  1. //
  2. // NSAttributedString+MLLabel.h
  3. // Pods
  4. //
  5. // Created by molon on 15/6/13.
  6. //
  7. //
  8. #import <Foundation/Foundation.h>
  9. #import <UIKit/UIKit.h>
  10. @interface NSAttributedString (MLLabel)
  11. + (instancetype)attributedStringWithHTML:(NSString*)htmlString;
  12. /**
  13. 根据一个链接相关的正则,返回链接化得AttributedString,linkRegex里一定要包含显示的内容用()包裹起来
  14. Example:
  15. NSString *str = @"张三的电话[tel=000000 name=tel1]李四的电话[tel=00444000 name=tel2]王五的电话[tel=000300 name=tel3]都在这了";
  16. NSRegularExpression *regex = [[NSRegularExpression alloc] initWithPattern:@"\\[tel=(\\d{6,11}) name=(\\w+)\\]" options:kNilOptions error:nil];
  17. self.label.attributedText = [str linkAttributedStringWithLinkRegex:regex groupIndexForDisplay:2 groupIndexForValue:1];
  18. */
  19. - (NSAttributedString*)linkAttributedStringWithLinkRegex:(NSRegularExpression*)linkRegex groupIndexForDisplay:(NSInteger)groupIndexForDisplay groupIndexForValue:(NSInteger)groupIndexForValue;
  20. @end