// // DDProtocolView.m // DingDangApp // // Created by apple on 2023/7/4. // #import "DDProtocolView.h" #import "DDAppColor.h" @implementation DDProtocolView - (instancetype)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { [self addSubview:self.protocolLabel]; [self addSubview:self.submitBtn]; [self.submitBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.height.width.mas_equalTo(44); make.centerY.equalTo(self); make.right.equalTo(self.protocolLabel.mas_left).inset(5); }]; } return self; } - (void)submitBtnClick { self.submitBtn.selected = !self.submitBtn.isSelected; } - (UIButton *)submitBtn { if (!_submitBtn) { _submitBtn = [UIButton buttonWithType:UIButtonTypeCustom]; [_submitBtn setImage:[UIImage imageNamed:@"login_checkbox_uncheck"] forState:UIControlStateNormal]; [_submitBtn setImage:[UIImage imageNamed:@"login_checkbox_checked"] forState:UIControlStateSelected]; [_submitBtn addTarget:self action:@selector(submitBtnClick) forControlEvents:UIControlEventTouchUpInside]; [_submitBtn setContentHorizontalAlignment:UIControlContentHorizontalAlignmentRight]; } return _submitBtn; } - (YYLabel *)protocolLabel { if (!_protocolLabel) { _protocolLabel = [[YYLabel alloc]init]; _protocolLabel.textColor = UIColor.whiteColor; _protocolLabel.font = DDFont(11); _protocolLabel.textAlignment = NSTextAlignmentCenter; CGFloat width = [ToolsObject sizeWithText:@"我已阅读《啵柚语音用户协议》和《啵柚语音隐私政策》" andFont:DDFont(12) maxSize:CGSizeMake(375, 44) andlineSpacing:2].width; _protocolLabel.frame = CGRectMake(0, 0, width, 44); _protocolLabel.centerX = kWidth/2+22; NSMutableAttributedString *text = [[NSMutableAttributedString alloc] initWithString:@"我已阅读《啵柚语音用户协议》和《啵柚语音隐私政策》"]; text.yy_alignment = NSTextAlignmentLeft; text.yy_color = DDHEXColor(0x999999); WeakSelf(ws) [text yy_setTextHighlightRange:[text.string rangeOfString:@"《啵柚语音用户协议》"] color:[DDAppColor dd_subTitleColor] backgroundColor:[UIColor whiteColor] userInfo:nil tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) { if (ws.userBlock) { ws.userBlock(); } } longPressAction:nil]; [text yy_setTextHighlightRange:[text.string rangeOfString:@"《啵柚语音隐私政策》"] color:[DDAppColor dd_subTitleColor] backgroundColor:[UIColor whiteColor] userInfo:nil tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) { if (ws.privacyBlock) { ws.privacyBlock(); } } longPressAction:nil]; _protocolLabel.attributedText = text; } return _protocolLabel; } /* // Only override drawRect: if you perform custom drawing. // An empty implementation adversely affects performance during animation. - (void)drawRect:(CGRect)rect { // Drawing code } */ @end