TDTextView.m 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. //
  2. // TDTextView.m
  3. // TheoryNetwork
  4. //
  5. // Created by tederen on 2019/9/27.
  6. // Copyright © 2019 tederen. All rights reserved.
  7. //
  8. #import "TDTextView.h"
  9. @interface TDTextView ()
  10. @end
  11. @implementation TDTextView
  12. - (instancetype)init
  13. {
  14. self = [super init];
  15. if (self) {
  16. }
  17. return self;
  18. }
  19. - (void)changLineSpacing
  20. {
  21. [self changLineSpacing:10 fontSize:15];
  22. }
  23. - (void)changLineSpacing:(CGFloat)padding fontSize:(CGFloat)fontSize
  24. {
  25. // 判断是否有候选字符,如果不为nil,代表有候选字符
  26. if(self.markedTextRange == nil){
  27. NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
  28. paragraphStyle.lineSpacing = padding; // 字体的行间距
  29. paragraphStyle.lineBreakMode = NSLineBreakByCharWrapping;
  30. NSDictionary *attributes = @{NSFontAttributeName:[UIFont systemFontOfSize:fontSize],
  31. NSParagraphStyleAttributeName:paragraphStyle
  32. };
  33. self.attributedText = [[NSAttributedString alloc] initWithString:self.text attributes:attributes];
  34. }
  35. }
  36. @end