| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173 |
- //
- // SetUserAgreementView.m
- // VclustersGemini
- //
- // Created by ypp on 2021/1/4.
- // Copyright © 2021 APPLE. All rights reserved.
- //
- #import "SetUserAgreementView.h"
- @implementation SetUserAgreementView
- @synthesize delegate;
- - (id)initWithFrame:(CGRect)frame{
- self = [super initWithFrame:CGRectMake(0, 0, SCREEN_W, 20)];
-
- if (self){
- [self setBackgroundColor:[UIColor clearColor]];
- [self drawView];
- }
-
- return self;
- }
- - (void)drawView{
- /*下方提示用户协议*/
- NSString *tipsStr = NSLocalizedString(@"log_have_read_deal",nil);
- NSString *optionalStr = NSLocalizedString(@"log_user_use_deal",nil);
- NSString *tipsStr1 = NSLocalizedString(@"log_use_and_deal",nil);
- NSString *privateStr = NSLocalizedString(@"log_use_secr_deal",nil);
- CGFloat titleFont = 12.f;
-
- /*计算字体的长度*/
- CGSize tipsStrSize = [tipsStr boundingRectWithSize:CGSizeMake(SCREEN_W/2.f, 20)
- options:(NSStringDrawingUsesLineFragmentOrigin)
- attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:titleFont]}
- context:nil].size;
-
- CGSize optionalStrSize = [optionalStr boundingRectWithSize:CGSizeMake(SCREEN_W/2.f, 20)
- options:(NSStringDrawingUsesLineFragmentOrigin)
- attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:titleFont]}
- context:nil].size;
-
- CGSize tipsStr1Size = [tipsStr1 boundingRectWithSize:CGSizeMake(SCREEN_W/2.f, 20)
- options:(NSStringDrawingUsesLineFragmentOrigin)
- attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:titleFont]}
- context:nil].size;
-
- CGSize privateStrSize = [privateStr boundingRectWithSize:CGSizeMake(SCREEN_W/2.f, 20)
- options:(NSStringDrawingUsesLineFragmentOrigin)
- attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:titleFont]}
- context:nil].size;
-
- CGFloat W_right_left = 37.f;
- UIButton *agreeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- [agreeBtn setBackgroundColor:[UIColor clearColor]];
- [agreeBtn setImage:[UIImage imageNamed:@"checkbox_default"] forState:UIControlStateNormal];
- [agreeBtn setImage:[UIImage imageNamed:@"checkbox_select"] forState:UIControlStateSelected];
- agreeBtn.adjustsImageWhenHighlighted = NO;
- [agreeBtn setBackgroundColor:[UIColor clearColor]];
- [agreeBtn addTarget:self
- action:@selector(agreeBtnPressed)
- forControlEvents:(UIControlEventTouchUpInside)];
- agreeBtn.adjustsImageWhenHighlighted = NO;
- [self addSubview:agreeBtn];
- [agreeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(W_right_left - 10);
- make.width.mas_equalTo(40);
- make.centerY.equalTo(self.mas_centerY);
- make.height.mas_equalTo(40);
- }];
- self.agreeBtn = agreeBtn;
-
- UILabel *tipsLabel0 = [[UILabel alloc] init];
- [tipsLabel0 setBackgroundColor:[UIColor clearColor]];
- [tipsLabel0 setTextColor:HW333333Color];
- [tipsLabel0 setFont:[UIFont systemFontOfSize:titleFont]];
- [tipsLabel0 setTextAlignment:(NSTextAlignmentRight)];
- [tipsLabel0 setText:tipsStr];
- [self addSubview:tipsLabel0];
- [tipsLabel0 mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(W_right_left + 20);
- make.width.mas_equalTo(tipsStrSize.width + 1.f);
- make.centerY.equalTo(self.mas_centerY);
- make.height.mas_equalTo(20);
- }];
-
- UIButton *optionalBtn = [[UIButton alloc] init];
- [optionalBtn setTitle:optionalStr forState:(UIControlStateNormal)];
- [optionalBtn setTitleColor:HW13B2EBColor forState:(UIControlStateNormal)];
- [optionalBtn.titleLabel setFont:[UIFont systemFontOfSize:titleFont]];
- [optionalBtn setBackgroundColor:[UIColor clearColor]];
- [optionalBtn addTarget:self
- action:@selector(optionalBtnPressed)
- forControlEvents:(UIControlEventTouchUpInside)];
- [self addSubview:optionalBtn];
- [optionalBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(tipsLabel0.mas_right);
- make.width.mas_equalTo(optionalStrSize.width + 1.f);
- make.centerY.equalTo(self.mas_centerY);
- make.height.mas_equalTo(20);
- }];
-
- UILabel *tipsLabel1 = [[UILabel alloc] init];
- [tipsLabel1 setBackgroundColor:[UIColor clearColor]];
- [tipsLabel1 setTextColor:HW333333Color];
- [tipsLabel1 setFont:[UIFont systemFontOfSize:titleFont]];
- [tipsLabel1 setTextAlignment:(NSTextAlignmentRight)];
- [tipsLabel1 setText:tipsStr1];
- [self addSubview:tipsLabel1];
- [tipsLabel1 mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(optionalBtn.mas_right);
- make.width.mas_equalTo(tipsStr1Size.width + 1.f);
- make.centerY.equalTo(self.mas_centerY);
- make.height.mas_equalTo(20);
- }];
-
- UIButton *privateBtn = [[UIButton alloc] init];
- [privateBtn setTitle:privateStr forState:(UIControlStateNormal)];
- [privateBtn setTitleColor:HW13B2EBColor forState:(UIControlStateNormal)];
- [privateBtn.titleLabel setFont:[UIFont systemFontOfSize:titleFont]];
- [privateBtn setBackgroundColor:[UIColor clearColor]];
- [privateBtn addTarget:self
- action:@selector(privateBtnPressed)
- forControlEvents:(UIControlEventTouchUpInside)];
- [self addSubview:privateBtn];
- [privateBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(tipsLabel1.mas_right);
- make.width.mas_equalTo(privateStrSize.width + 1.f);
- make.centerY.equalTo(self.mas_centerY);
- make.height.mas_equalTo(20);
- }];
- [self refreshUI];
- }
- //是否同意协议
- - (void)agreeBtnPressed{
- self.agreeBtn.selected = !self.agreeBtn.selected;
-
- [HWDataManager setNumberWithKey:Const_lastSetUserAgreementView value:[NSNumber numberWithBool:self.agreeBtn.selected]];
- }
- //用户使用协议
- - (void)optionalBtnPressed{
- HLog(@"\n----协议按钮被点击-------");
- if ([delegate respondsToSelector:@selector(optionalBtnPressed)]){
- [delegate optionalBtnPressed];
- }
- }
- //隐私协议
- - (void)privateBtnPressed{
- HLog(@"\n----协议按钮被点击-------");
-
- if ([delegate respondsToSelector:@selector(privateBtnPressed)]){
- [delegate privateBtnPressed];
- }
- }
- - (void)refreshUI{
- NSNumber *agreement = [HWDataManager getNumberWithKey:Const_lastSetUserAgreementView];
- if ([agreement boolValue]) { //同意协议
- [self.agreeBtn setSelected:YES];
- }
- else{
- [self.agreeBtn setSelected:NO];
- }
- }
- @end
|