SetUserAgreementView.m 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. //
  2. // SetUserAgreementView.m
  3. // VclustersGemini
  4. //
  5. // Created by ypp on 2021/1/4.
  6. // Copyright © 2021 APPLE. All rights reserved.
  7. //
  8. #import "SetUserAgreementView.h"
  9. @implementation SetUserAgreementView
  10. @synthesize delegate;
  11. - (id)initWithFrame:(CGRect)frame{
  12. self = [super initWithFrame:CGRectMake(0, 0, SCREEN_W, 20)];
  13. if (self){
  14. [self setBackgroundColor:[UIColor clearColor]];
  15. [self drawView];
  16. }
  17. return self;
  18. }
  19. - (void)drawView{
  20. /*下方提示用户协议*/
  21. NSString *tipsStr = NSLocalizedString(@"log_have_read_deal",nil);
  22. NSString *optionalStr = NSLocalizedString(@"log_user_use_deal",nil);
  23. NSString *tipsStr1 = NSLocalizedString(@"log_use_and_deal",nil);
  24. NSString *privateStr = NSLocalizedString(@"log_use_secr_deal",nil);
  25. CGFloat titleFont = 12.f;
  26. /*计算字体的长度*/
  27. CGSize tipsStrSize = [tipsStr boundingRectWithSize:CGSizeMake(SCREEN_W/2.f, 20)
  28. options:(NSStringDrawingUsesLineFragmentOrigin)
  29. attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:titleFont]}
  30. context:nil].size;
  31. CGSize optionalStrSize = [optionalStr boundingRectWithSize:CGSizeMake(SCREEN_W/2.f, 20)
  32. options:(NSStringDrawingUsesLineFragmentOrigin)
  33. attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:titleFont]}
  34. context:nil].size;
  35. CGSize tipsStr1Size = [tipsStr1 boundingRectWithSize:CGSizeMake(SCREEN_W/2.f, 20)
  36. options:(NSStringDrawingUsesLineFragmentOrigin)
  37. attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:titleFont]}
  38. context:nil].size;
  39. CGSize privateStrSize = [privateStr boundingRectWithSize:CGSizeMake(SCREEN_W/2.f, 20)
  40. options:(NSStringDrawingUsesLineFragmentOrigin)
  41. attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:titleFont]}
  42. context:nil].size;
  43. CGFloat W_right_left = 37.f;
  44. UIButton *agreeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  45. [agreeBtn setBackgroundColor:[UIColor clearColor]];
  46. [agreeBtn setImage:[UIImage imageNamed:@"checkbox_default"] forState:UIControlStateNormal];
  47. [agreeBtn setImage:[UIImage imageNamed:@"checkbox_select"] forState:UIControlStateSelected];
  48. agreeBtn.adjustsImageWhenHighlighted = NO;
  49. [agreeBtn setBackgroundColor:[UIColor clearColor]];
  50. [agreeBtn addTarget:self
  51. action:@selector(agreeBtnPressed)
  52. forControlEvents:(UIControlEventTouchUpInside)];
  53. agreeBtn.adjustsImageWhenHighlighted = NO;
  54. [self addSubview:agreeBtn];
  55. [agreeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  56. make.left.mas_equalTo(W_right_left - 10);
  57. make.width.mas_equalTo(40);
  58. make.centerY.equalTo(self.mas_centerY);
  59. make.height.mas_equalTo(40);
  60. }];
  61. self.agreeBtn = agreeBtn;
  62. UILabel *tipsLabel0 = [[UILabel alloc] init];
  63. [tipsLabel0 setBackgroundColor:[UIColor clearColor]];
  64. [tipsLabel0 setTextColor:HW333333Color];
  65. [tipsLabel0 setFont:[UIFont systemFontOfSize:titleFont]];
  66. [tipsLabel0 setTextAlignment:(NSTextAlignmentRight)];
  67. [tipsLabel0 setText:tipsStr];
  68. [self addSubview:tipsLabel0];
  69. [tipsLabel0 mas_makeConstraints:^(MASConstraintMaker *make) {
  70. make.left.mas_equalTo(W_right_left + 20);
  71. make.width.mas_equalTo(tipsStrSize.width + 1.f);
  72. make.centerY.equalTo(self.mas_centerY);
  73. make.height.mas_equalTo(20);
  74. }];
  75. UIButton *optionalBtn = [[UIButton alloc] init];
  76. [optionalBtn setTitle:optionalStr forState:(UIControlStateNormal)];
  77. [optionalBtn setTitleColor:HW13B2EBColor forState:(UIControlStateNormal)];
  78. [optionalBtn.titleLabel setFont:[UIFont systemFontOfSize:titleFont]];
  79. [optionalBtn setBackgroundColor:[UIColor clearColor]];
  80. [optionalBtn addTarget:self
  81. action:@selector(optionalBtnPressed)
  82. forControlEvents:(UIControlEventTouchUpInside)];
  83. [self addSubview:optionalBtn];
  84. [optionalBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  85. make.left.mas_equalTo(tipsLabel0.mas_right);
  86. make.width.mas_equalTo(optionalStrSize.width + 1.f);
  87. make.centerY.equalTo(self.mas_centerY);
  88. make.height.mas_equalTo(20);
  89. }];
  90. UILabel *tipsLabel1 = [[UILabel alloc] init];
  91. [tipsLabel1 setBackgroundColor:[UIColor clearColor]];
  92. [tipsLabel1 setTextColor:HW333333Color];
  93. [tipsLabel1 setFont:[UIFont systemFontOfSize:titleFont]];
  94. [tipsLabel1 setTextAlignment:(NSTextAlignmentRight)];
  95. [tipsLabel1 setText:tipsStr1];
  96. [self addSubview:tipsLabel1];
  97. [tipsLabel1 mas_makeConstraints:^(MASConstraintMaker *make) {
  98. make.left.mas_equalTo(optionalBtn.mas_right);
  99. make.width.mas_equalTo(tipsStr1Size.width + 1.f);
  100. make.centerY.equalTo(self.mas_centerY);
  101. make.height.mas_equalTo(20);
  102. }];
  103. UIButton *privateBtn = [[UIButton alloc] init];
  104. [privateBtn setTitle:privateStr forState:(UIControlStateNormal)];
  105. [privateBtn setTitleColor:HW13B2EBColor forState:(UIControlStateNormal)];
  106. [privateBtn.titleLabel setFont:[UIFont systemFontOfSize:titleFont]];
  107. [privateBtn setBackgroundColor:[UIColor clearColor]];
  108. [privateBtn addTarget:self
  109. action:@selector(privateBtnPressed)
  110. forControlEvents:(UIControlEventTouchUpInside)];
  111. [self addSubview:privateBtn];
  112. [privateBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  113. make.left.mas_equalTo(tipsLabel1.mas_right);
  114. make.width.mas_equalTo(privateStrSize.width + 1.f);
  115. make.centerY.equalTo(self.mas_centerY);
  116. make.height.mas_equalTo(20);
  117. }];
  118. [self refreshUI];
  119. }
  120. //是否同意协议
  121. - (void)agreeBtnPressed{
  122. self.agreeBtn.selected = !self.agreeBtn.selected;
  123. [HWDataManager setNumberWithKey:Const_lastSetUserAgreementView value:[NSNumber numberWithBool:self.agreeBtn.selected]];
  124. }
  125. //用户使用协议
  126. - (void)optionalBtnPressed{
  127. HLog(@"\n----协议按钮被点击-------");
  128. if ([delegate respondsToSelector:@selector(optionalBtnPressed)]){
  129. [delegate optionalBtnPressed];
  130. }
  131. }
  132. //隐私协议
  133. - (void)privateBtnPressed{
  134. HLog(@"\n----协议按钮被点击-------");
  135. if ([delegate respondsToSelector:@selector(privateBtnPressed)]){
  136. [delegate privateBtnPressed];
  137. }
  138. }
  139. - (void)refreshUI{
  140. NSNumber *agreement = [HWDataManager getNumberWithKey:Const_lastSetUserAgreementView];
  141. if ([agreement boolValue]) { //同意协议
  142. [self.agreeBtn setSelected:YES];
  143. }
  144. else{
  145. [self.agreeBtn setSelected:NO];
  146. }
  147. }
  148. @end