RADetailSingleLineModel.m 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. //
  2. // RADetailSingleLineModel.m
  3. // Apex And Drivers
  4. //
  5. // Created by Jack on 2018/6/2.
  6. // Copyright © 2018年 USAI. All rights reserved.
  7. //
  8. #import "RADetailSingleLineModel.h"
  9. static const CGFloat SpaceWidth = 10.0f;
  10. static const CGFloat SpaceHeight = 38.0f;
  11. @implementation RADetailSingleLineModel {
  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. CGFloat w = self.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:15.0f]}
  34. context:nil].size.height;
  35. _height = h + SpaceHeight;
  36. if (_height < 70.0f) {
  37. _height = 70.0f;
  38. }
  39. }
  40. @end