RADetailLocationModel.m 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. //
  2. // RADetailLocationModel.m
  3. // Apex And Drivers
  4. //
  5. // Created by Jack on 2018/6/2.
  6. // Copyright © 2018年 USAI. All rights reserved.
  7. //
  8. #import "RADetailLocationModel.h"
  9. static const CGFloat SpaceWidth = 90.0f;
  10. static const CGFloat SpaceHeight = 38.0f;
  11. @implementation RADetailLocationModel {
  12. CGFloat _height;
  13. }
  14. - (void)setLocation:(NSString *)location {
  15. _location = location;
  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.location.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.location boundingRectWithSize:CGSizeMake(w - SpaceWidth, FLT_MAX)
  35. options:(NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading)
  36. attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:15.0f]}
  37. context:nil].size.height;
  38. CGFloat navBtnHeight = 30.0f;
  39. if (h < navBtnHeight) { // navigation button height
  40. h = navBtnHeight;
  41. }
  42. _height = h + SpaceHeight;
  43. if (_height < 100.0f) {
  44. _height = 100.0f;
  45. }
  46. }
  47. @end