CommonLocationView.m 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. //
  2. // CommonLocationView.m
  3. // UniversalApp
  4. //
  5. // Created by bogokj on 2019/12/20.
  6. // Copyright © 2019 voidcat. All rights reserved.
  7. //
  8. #import "CommonLocationView.h"
  9. @interface CommonLocationView ()
  10. @property (strong, nonatomic) UIImageView *locationBgImageView;
  11. @property (strong, nonatomic) UIImageView *locationImageView;
  12. @property (strong, nonatomic) UILabel *locationLabel;
  13. @end
  14. @implementation CommonLocationView
  15. - (instancetype)initWithFrame:(CGRect)frame{
  16. if (self = [super initWithFrame:frame]) {
  17. }
  18. return self;
  19. }
  20. - (void)setLocation:(NSString *)location{
  21. _location = location;
  22. // if (![self.subviews containsObject:self.locationBgImageView]) {
  23. // [self addSubview:self.locationBgImageView];
  24. // }
  25. if (![self.subviews containsObject:self.locationImageView]) {
  26. [self addSubview:self.locationImageView];
  27. }
  28. if (![self.subviews containsObject:self.locationLabel]) {
  29. [self addSubview:self.locationLabel];
  30. }
  31. // [self.locationBgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  32. // make.edges.equalTo(self);
  33. // }];
  34. [self.locationImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  35. make.left.equalTo(self).offset(0);
  36. make.width.equalTo(@(9.5));
  37. make.centerY.equalTo(self);
  38. make.height.equalTo(@(13));
  39. }];
  40. [self.locationLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  41. make.left.equalTo(self.locationImageView.mas_right).offset(5);
  42. make.top.bottom.equalTo(self);
  43. make.right.equalTo(self).offset(-5);
  44. }];
  45. [self.locationLabel setText:location];
  46. }
  47. - (CGSize)sizeThatFits:(CGSize)size{
  48. CGSize lableSize = [self.locationLabel sizeThatFits:size];
  49. return CGSizeMake(18 + lableSize.width + 5, 15);
  50. }
  51. - (UIImageView *)locationBgImageView{
  52. if (!_locationBgImageView) {
  53. _locationBgImageView = [[UIImageView alloc]initWithFrame:CGRectZero];
  54. _locationBgImageView.contentMode = UIViewContentModeScaleToFill;
  55. _locationBgImageView.image = [UIImage imageNamed:@"address1"];
  56. }
  57. return _locationBgImageView;
  58. }
  59. - (UIImageView *)locationImageView{
  60. if (!_locationImageView) {
  61. _locationImageView = [[UIImageView alloc]initWithFrame:CGRectZero];
  62. _locationImageView.image = [UIImage imageNamed:@"address"];
  63. }
  64. return _locationImageView;
  65. }
  66. - (UILabel *)locationLabel{
  67. if (!_locationLabel) {
  68. _locationLabel = [[UILabel alloc]initWithFrame:CGRectZero];
  69. _locationLabel.textColor = [UIColor colorWithHexString:@"#666666"];
  70. _locationLabel.font = [UIFont systemFontOfSize:12 weight:UIFontWeightMedium];
  71. _locationLabel.textAlignment = NSTextAlignmentRight;
  72. }
  73. return _locationLabel;
  74. }
  75. @end