RAEditLabelModel.m 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. //
  2. // RAEditLabelModel.m
  3. // Apex And Drivers
  4. //
  5. // Created by Jack on 2018/6/4.
  6. // Copyright © 2018年 USAI. All rights reserved.
  7. //
  8. #import "RAEditLabelModel.h"
  9. static const CGFloat SpaceWidth = 10.0f;
  10. static const CGFloat SpaceHeight = 40.0f;
  11. @implementation RAEditLabelModel {
  12. CGFloat _height;
  13. }
  14. - (CGFloat)height {
  15. if (_height <= 0) {
  16. [self caculateValueHeight];
  17. }
  18. return _height;
  19. }
  20. - (void)setValue:(NSString *)value {
  21. _value = value;
  22. dispatch_async(dispatch_get_global_queue(0, 0), ^{
  23. [self caculateValueHeight];
  24. });
  25. }
  26. - (void)caculateValueHeight {
  27. CGFloat w = [UIScreen mainScreen].bounds.size.width;
  28. if (w <= 0) {
  29. w = CGRectGetWidth([UIScreen mainScreen].bounds);
  30. }
  31. CGFloat h = [self.value boundingRectWithSize:CGSizeMake(w - SpaceWidth, FLT_MAX)
  32. options:(NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading)
  33. attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:14.0f]}
  34. context:nil].size.height;
  35. _height = h + SpaceHeight;
  36. if (_height < 55.0f) {
  37. _height = 55.0f;
  38. }
  39. }
  40. @end