BuildingCell.m 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. //
  2. // BuildingCell.m
  3. // IBOSS
  4. //
  5. // Created by 关宏厚 on 2020/7/27.
  6. // Copyright © 2020 elongtian. All rights reserved.
  7. //
  8. #import "BuildingCell.h"
  9. @interface BuildingCell(){
  10. // 背景色view
  11. UIView *_viewBackgroud;
  12. // 宽度
  13. CGFloat _width;
  14. // 高度
  15. CGFloat _lheight ;
  16. // x坐标
  17. CGFloat _lblx;
  18. }
  19. @end
  20. @implementation BuildingCell
  21. /**
  22. 初始化
  23. @param style <#style description#>
  24. @param reuseIdentifier <#reuseIdentifier description#>
  25. @return <#return value description#>
  26. */
  27. - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
  28. _lblx = 20;
  29. _lheight = 25;
  30. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  31. _buildingLabelView= [[UILabel alloc] initWithFrame:CGRectMake(_lblx,3,70,_lheight)];
  32. _buildingLabelView.backgroundColor = [UIColor clearColor];
  33. _buildingLabelView.textColor = [UIColor blackColor];
  34. _buildingLabelView .text = @"门 牌 号:";
  35. _buildingLabelView .font = [UIFont systemFontOfSize:LabelFontOfSize];
  36. [self addSubview:_buildingLabelView];
  37. _width = Screen_Width - CGRectGetMaxX(_buildingLabelView.frame) - _lblx;
  38. _buildingView = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(_buildingLabelView.frame)+3,3,_width,_lheight)];
  39. _buildingView.backgroundColor = [UIColor clearColor];
  40. _buildingView.textColor = [UIColor blackColor];
  41. _buildingView.textAlignment = NSTextAlignmentLeft;
  42. _buildingView.font = [UIFont systemFontOfSize:LabelFontOfSize];
  43. _buildingView.numberOfLines =0;
  44. [self addSubview: _buildingView];
  45. _viewBackgroud = [UIView new];
  46. _viewBackgroud.frame = CGRectMake(_lblx, CGRectGetMaxY(_buildingView.frame)+1, Screen_Width-2*_lblx, 1);
  47. _viewBackgroud.backgroundColor = LineBackgroundColor;
  48. [self addSubview:_viewBackgroud];
  49. return self;
  50. }
  51. /**
  52. 重新设置地址的高度
  53. @param address <#address description#>
  54. */
  55. - (void)setBuilding:(NSString *)building{
  56. _buildingView.text=building;
  57. NSDictionary *attributesDict = @{NSFontAttributeName:[UIFont systemFontOfSize: LabelFontOfSize]};
  58. CGRect fra = [building boundingRectWithSize:CGSizeMake(_width, MAXFLOAT) options:NSStringDrawingTruncatesLastVisibleLine | NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading attributes:attributesDict context:nil ];
  59. CGFloat h = fra.size.height;
  60. if (fra.size.height < _lheight) {
  61. h = _lheight;
  62. }else{
  63. h = fra.size.height;
  64. }
  65. _buildingView.frame = CGRectMake(CGRectGetMaxX(_buildingLabelView.frame) + 3,3,_width ,h);
  66. _viewBackgroud.frame = CGRectMake(_lblx, CGRectGetMaxY(_buildingView.frame) + 2, Screen_Width - 2*_lblx, 1);
  67. self.height = CGRectGetMaxY(_viewBackgroud.frame);
  68. }
  69. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  70. [super setSelected:selected animated:animated];
  71. }
  72. @end