RADetailLocationModel.m 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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 = 60.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. // NSArray *tmpArr = [location componentsSeparatedByString:@"TEL:"];
  20. // NSString *tmpStr = [tmpArr objectAtIndex:0];
  21. // tmpArr = [tmpStr componentsSeparatedByString:@"\r\n"];
  22. // NSMutableArray *tmpMArr = [tmpArr mutableCopy];
  23. // [tmpMArr removeObjectAtIndex:0];
  24. // tmpStr = [tmpMArr componentsJoinedByString:@" "];
  25. // self.street = tmpStr;
  26. }
  27. - (CGFloat)height {
  28. if (_height <= 0) {
  29. [self caculateValueHeight];
  30. }
  31. return _height;
  32. }
  33. - (void)caculateValueHeight {
  34. // if (self.location.length == 0) {
  35. // return;
  36. // }
  37. CGFloat w = self.width;
  38. if (w <= 0) {
  39. w = CGRectGetWidth([UIScreen mainScreen].bounds);
  40. }
  41. CGFloat h = [self.location boundingRectWithSize:CGSizeMake(w - SpaceWidth, FLT_MAX)
  42. options:(NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading)
  43. attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:15.0f]}
  44. context:nil].size.height;
  45. CGFloat navBtnHeight = 40.0f;
  46. if (h < navBtnHeight) { // navigation button height
  47. h = navBtnHeight;
  48. }
  49. _height = h + SpaceHeight;
  50. if (_height < 80.0f) {
  51. _height = 80.0f;
  52. }
  53. }
  54. @end