// // HDLESDetectionTypeHeaderView.m // EZSDK // // Created by Davin on 2024/12/17. // #import "HDLESDetectionTypeHeaderView.h" @interface HDLESDetectionTypeHeaderView () @property (nonatomic, strong) UILabel *titleLabel; @property (nonatomic, strong) UISwitch *detectionSwitch; @property (nonatomic, copy)void(^switchBlock)(BOOL isSelected); @end @implementation HDLESDetectionTypeHeaderView - (instancetype)initWithFrame:(CGRect)frame { if (self = [super initWithFrame:frame]) { [self createSubviews]; } return self; } - (void)createSubviews { [self addSubview:self.titleLabel]; [self addSubview:self.detectionSwitch]; [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(self.mas_left).offset(16); make.centerY.mas_equalTo(self.mas_centerY); }]; [self.detectionSwitch mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_greaterThanOrEqualTo(self.titleLabel.mas_right).offset(16); make.right.mas_equalTo(self.mas_right); make.centerY.mas_equalTo(self.titleLabel.mas_centerY); make.width.mas_equalTo(70); make.height.mas_equalTo(28); }]; [self.detectionSwitch addTarget:self action:@selector(detectionSwitchAction:) forControlEvents:UIControlEventValueChanged]; } #pragma mark - PublishMethod - (void)configSelected:(BOOL)isSelected { [self.detectionSwitch setOn:isSelected]; } /// 检测信息设置 /// - Parameters: /// - detectionType: 检测类型 /// - isSelected: 是否选中 - (void)configSelected:(BOOL)isSelected switchResult:(void(^)(BOOL isSelected))result { self.switchBlock = result; [self.detectionSwitch setOn:isSelected]; } #pragma mark - PrivateMethod - (void)detectionSwitchAction:(UISwitch *)sender { if (self.switchBlock) { self.switchBlock(sender.isOn); } } #pragma mark - Getter - (UILabel *)titleLabel { if (!_titleLabel) { _titleLabel=[[UILabel alloc] init]; _titleLabel.font = HDLEZ_Get_FontRegularWithSize(HDLEZ_FontSize_14); _titleLabel.textColor=HDLEZ_COLOR_TITLE_BLACK; _titleLabel.text = NSLocalizedString(@"setting_action_detect", @"活动检测提醒"); } return _titleLabel; } - (UISwitch *)detectionSwitch { if (!_detectionSwitch) { _detectionSwitch = [[UISwitch alloc] initWithFrame:CGRectZero]; _detectionSwitch.on = NO; } return _detectionSwitch; } @end