RADetailMultLineModel.m 1.2 KB

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