SensorListCell.m 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. //
  2. // SensorListCell.m
  3. // FunSDKDemo
  4. //
  5. // Created by Megatron on 2019/3/25.
  6. // Copyright © 2019 Megatron. All rights reserved.
  7. //
  8. #import "SensorListCell.h"
  9. #import <Masonry/Masonry.h>
  10. @implementation SensorListCell
  11. - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
  12. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  13. if (self) {
  14. [self addSubview:self.lbTitle];
  15. [self addSubview:self.statueSwitch];
  16. [self myLayout];
  17. }
  18. return self;
  19. }
  20. #pragma mark - Layout
  21. - (void)myLayout{
  22. [self.lbTitle mas_makeConstraints:^(MASConstraintMaker *make) {
  23. make.centerY.equalTo(self);
  24. make.left.equalTo(self).mas_offset(20);
  25. make.width.equalTo(self).multipliedBy(0.6);
  26. make.height.equalTo(@40);
  27. }];
  28. [self.statueSwitch mas_makeConstraints:^(MASConstraintMaker *make) {
  29. make.centerY.equalTo(self);
  30. make.right.equalTo(self).mas_offset(-10);
  31. }];
  32. }
  33. #pragma mark - EventAction
  34. - (void)statueSwitchClicked:(UISwitch *)mySwitch{
  35. if (self.statueAction) {
  36. self.statueAction(mySwitch.isOn ? 1 : 0, self.indexRow);
  37. }
  38. }
  39. - (void)listenStatue:(SensorSwitchStatueCallBack)action{
  40. self.statueAction = action;
  41. }
  42. #pragma mark - LazyLoad
  43. - (UILabel *)lbTitle{
  44. if (!_lbTitle) {
  45. _lbTitle = [[UILabel alloc] init];
  46. _lbTitle.font = [UIFont systemFontOfSize:18];
  47. }
  48. return _lbTitle;
  49. }
  50. - (UISwitch *)statueSwitch{
  51. if (!_statueSwitch) {
  52. _statueSwitch = [[UISwitch alloc] init];
  53. [_statueSwitch addTarget:self action:@selector(statueSwitchClicked:) forControlEvents:UIControlEventValueChanged];
  54. }
  55. return _statueSwitch;
  56. }
  57. @end