EdgeInsetsLabel.m 793 B

1234567891011121314151617181920212223242526272829303132
  1. //
  2. // EdgeInsetsLabel.m
  3. // BuguLive
  4. //
  5. // Created by yy on 17/1/6.
  6. // Copyright © 2017年 xfg. All rights reserved.
  7. //
  8. #import "EdgeInsetsLabel.h"
  9. @implementation EdgeInsetsLabel
  10. - (CGRect)textRectForBounds:(CGRect)bounds limitedToNumberOfLines:(NSInteger)numberOfLines
  11. {
  12. UIEdgeInsets insets = self.edgeInsets;
  13. CGRect rect = [super textRectForBounds:UIEdgeInsetsInsetRect(bounds, insets)
  14. limitedToNumberOfLines:numberOfLines];
  15. rect.origin.x -= insets.left;
  16. rect.origin.y -= insets.top;
  17. rect.size.width += (insets.left + insets.right);
  18. rect.size.height += (insets.top + insets.bottom);
  19. return rect;
  20. }
  21. - (void)drawTextInRect:(CGRect)rect
  22. {
  23. [super drawTextInRect:UIEdgeInsetsInsetRect(rect, self.edgeInsets)];
  24. }
  25. @end