TableheaderView.m 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. //
  2. // TableheaderView.m
  3. // Haishenghai-master
  4. //
  5. // Created by GG on 2019/1/5.
  6. // Copyright © 2019年 Haishenghai intelligence network technology. All rights reserved.
  7. //
  8. #import "TableheaderView.h"
  9. #define ScreenWidth [UIScreen mainScreen].bounds.size.width
  10. #define ScreenHeight [UIScreen mainScreen].bounds.size.height
  11. @implementation TableheaderView
  12. -(instancetype)initWithFrame:(CGRect)frame{
  13. if (self = [super initWithFrame:frame]) {
  14. _nameLabel = [[UILabel alloc]init];
  15. // _nameLabel.text = @"独立式烟雾探测报警器";
  16. _nameLabel.textAlignment = NSTextAlignmentLeft;
  17. _nameLabel.font = [UIFont systemFontOfSize:16];
  18. [self addSubview:_nameLabel];
  19. _stateLabel = [[UILabel alloc]init];
  20. // _stateLabel.text = @"正常";
  21. _stateLabel.font = [UIFont systemFontOfSize:16];
  22. _stateLabel.textColor = [UIColor blueColor];
  23. [self addSubview:_stateLabel];
  24. _image =[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"hsh_home_equipmentdetails"]];
  25. [self addSubview:_image];
  26. //四个标题
  27. for (int i=0; i<4; i++) {
  28. UILabel *titlelab= [[UILabel alloc]init];
  29. titlelab.frame = CGRectMake(70+(75)*(i/4), 30+(20)*(i%4), 75, 20);
  30. NSArray *titles = @[@"运 营 商:",@"编 号:",@"位 置:",@"详细地址:"];
  31. titlelab.text = titles[i];
  32. titlelab.font = [UIFont systemFontOfSize:14];
  33. [self addSubview:titlelab];
  34. }
  35. //四个内容
  36. for (int i=0; i<2; i++) {
  37. UILabel *nameLabel= [[UILabel alloc]init];
  38. nameLabel.frame = CGRectMake((ScreenWidth-100)+(75)*(i/2), 30+(20)*(i%2), 75, 20);
  39. NSArray *titles = @[@"电池电压:",@"网关状态:"];
  40. nameLabel.text = titles[i];
  41. nameLabel.font = [UIFont systemFontOfSize:14];
  42. [self addSubview:nameLabel];
  43. }
  44. _recordLabel= [[UILabel alloc]init];
  45. _recordLabel.frame = CGRectMake((ScreenWidth-35), 30, 35, 20);
  46. _recordLabel.text = @"3.0V";
  47. _recordLabel.font = [UIFont systemFontOfSize:14];
  48. [self addSubview:_recordLabel];
  49. _gatewayLabel= [[UILabel alloc]init];
  50. _gatewayLabel.frame = CGRectMake((ScreenWidth-35), 50, 35, 20);
  51. _gatewayLabel.text = @"离线";
  52. _gatewayLabel.font = [UIFont systemFontOfSize:14];
  53. [self addSubview:_gatewayLabel];
  54. //第一列四个内容
  55. _detailLabel = [[UILabel alloc]init];
  56. _detailLabel.frame = CGRectMake(140, 30,125 , 20);
  57. _detailLabel.text = @"电信NB-IOT";
  58. // _detailLabel.backgroundColor = [UIColor purpleColor];
  59. _detailLabel.font = [UIFont systemFontOfSize:14];
  60. [self addSubview:_detailLabel];
  61. _numberLabel = [[UILabel alloc]init];
  62. _numberLabel.frame = CGRectMake(140, 50,140 , 20);
  63. // _numberLabel.text = @"编号";
  64. _numberLabel.font = [UIFont systemFontOfSize:14];
  65. [self addSubview:_numberLabel];
  66. _locationLabel = [[UILabel alloc]init];
  67. _locationLabel.frame = CGRectMake(140, 70,200 , 20);
  68. // _locationLabel.text = @"位置";
  69. _locationLabel.font = [UIFont systemFontOfSize:14];
  70. [self addSubview:_locationLabel];
  71. _d_locationLabel = [[UILabel alloc]init];
  72. _d_locationLabel.frame = CGRectMake(140, 90,200 , 20);
  73. // _d_locationLabel.text = @"位置";
  74. _d_locationLabel.font = [UIFont systemFontOfSize:14];
  75. [self addSubview:_d_locationLabel];
  76. UIView *lineView = [[UIView alloc]init];
  77. lineView.frame = CGRectMake(0, 110, ScreenWidth, 0.5);
  78. lineView.backgroundColor = [UIColor lightGrayColor];
  79. [self addSubview:lineView];
  80. }
  81. return self;
  82. }
  83. //在这里添加frame和约束
  84. -(void)layoutSubviews{
  85. _nameLabel.frame = CGRectMake(10, 5, ScreenWidth-100, 25);
  86. _stateLabel.frame = CGRectMake(ScreenWidth-40, 5, 40, 25);
  87. _image.frame = CGRectMake(0, 30, 70, 70);
  88. }
  89. //加载数据
  90. //- (void)setTopic: (SYDTopic *)topic
  91. //{
  92. // _topic = topic; // 注意在这个方法中,不写这句也是没有问题的,因为在下面的语句使用的是topic而非self.topic或_topic,但是如果在其他的方法中也想要访问topic这个属性,那么就需要写上,否则self.topic或_topic会一直是nil(因为出了这个方法的作用域,topic就销毁了,如果再想访问需要有其他的引用指向它)。所以建议,要写上这句。
  93. //
  94. // [self.button setTitle: topic.like forState...];
  95. // self.nameLabel = topic.name;
  96. //}
  97. /*
  98. // Only override drawRect: if you perform custom drawing.
  99. // An empty implementation adversely affects performance during animation.
  100. - (void)drawRect:(CGRect)rect {
  101. // Drawing code
  102. }
  103. */
  104. /**
  105. *总结
  106. initWithFrame:中添加子控件。
  107. layoutSubviews中设置子控件frame。
  108. 对外设置数据接口,重写setter方法给子控件设置显示数据。
  109. 在view controller里面使用init/initWithFrame:方法创建自定义类,并且给自定义类的frame赋值。
  110. 对自定义类对外暴露的数据接口进行赋值即可。
  111. *
  112. */
  113. @end