NSString+MLLabel.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  1. //
  2. // NSString+MLLabel.h
  3. // Pods
  4. //
  5. // Created by molon on 15/6/13.
  6. //
  7. //
  8. #import <Foundation/Foundation.h>
  9. @interface NSString (MLLabel)
  10. //这个只是由于换行符的原因所必须有的行数
  11. - (NSUInteger)lineCount;
  12. //拿到某行之前的字符串
  13. - (NSString*)subStringToLineIndex:(NSUInteger)lineIndex;
  14. //拿到某行之前的字符串的长度
  15. - (NSUInteger)lengthToLineIndex:(NSUInteger)lineIndex;
  16. //是否最后字符属于换行符
  17. - (BOOL)isNewlineCharacterAtEnd;
  18. /**
  19. 根据一个链接相关的正则,返回链接化得AttributedString,linkRegex里一定要包含显示的内容用()包裹起来
  20. Example:
  21. NSString *str = @"张三的电话[tel=000000 name=tel1]李四的电话[tel=00444000 name=tel2]王五的电话[tel=000300 name=tel3]都在这了";
  22. NSRegularExpression *regex = [[NSRegularExpression alloc] initWithPattern:@"\\[tel=(\\d{6,11}) name=(\\w+)\\]" options:kNilOptions error:nil];
  23. self.label.attributedText = [str linkAttributedStringWithLinkRegex:regex groupIndexForDisplay:2 groupIndexForValue:1];
  24. */
  25. - (NSAttributedString*)linkAttributedStringWithLinkRegex:(NSRegularExpression*)linkRegex groupIndexForDisplay:(NSInteger)groupIndexForDisplay groupIndexForValue:(NSInteger)groupIndexForValue;
  26. @end